As you said, if let's say concatenation works flawlessly with a Class as it
does with String, I don't see any other reason to subclass String.As far as
the class design goes, I would like an approach like:
URI = Base, abstract class.
URI.URL = extends URI for the URL scheme
URI.Email = extends URI for the email scheme
and user can also extend it for the scheme he deals with.
Since the API changes for each scheme (the name of the parts that you can
get), I don't see the point of having all the logic into URI. It's not like
the method get('username') will work for all schemes, hence why it's a good
idea to inherit from URI.
Also, from FormValidator we could do something like:
try {
new Email(email_value);
} catch(e){
this.error('wrong email');
}
In any case, we can also use URI as a factory to create instances for a
scheme
URI.create('http://', 'url');
URI.create('http://', 'email');
On Wed, Mar 11, 2009 at 1:59 AM, Thomas Aylott <[email protected]
> wrote:
>
> The biggest issue is consistency.
> Nothing else in MooTools subclasses String.
> This is More and not Core, so the rules aren't as hard and fast.
> But I don't think I want to recommend that people subclass string.
>
> It all boils down to who is going to write all the specs and maintain this
> thing into the future.
> I'm not going to, so I don't get a real vote.
>
> All I really need it to do is handle the stuff I want. I'd rather not have
> to use toString() on it if I don't have to.
> If I don't have to do that with a normal Class, then what's the point of it
> being a string subclass?
>
> —Thomas Aylott / subtleGradient
>
>
> On Mar 10, 2009, at 11:12 PM, Sebastian Markbåge wrote:
>
> About concatenation. I just added a test for that. new Uri('...') +
>> 'string' and 'string' + new Uri('...') both work as expected. So
>> assuming it is two strings being concatenated it will work anyway. You
>> can also use it to test a regexp: (/^...$/).test(new Uri('...'))
>>
>> So I guess we're down to whether or not the String-manipulation
>> methods such as substr, replace etc. are needed. And that boils down
>> to whether or not a URI is a String?
>>
>
--
Guillermo Rauch
http://devthought.com