Re: Wisdom of overriding isEqual:
Re: Wisdom of overriding isEqual:
- Subject: Re: Wisdom of overriding isEqual:
- From: j o a r <email@hidden>
- Date: Wed, 10 Mar 2004 14:18:01 +0100
On 2004-03-10, at 13.33, Patrick Machielse wrote:
>
1) NSObject implements this method as:
>
- (BOOL)isEqual:(id)anObject
>
{
>
return self == anObject;
>
}
The fallback implementation of isEqual compares pointers, that is
correct.
>
2) No standard Cocoa class overrides isEqual:, at least the
>
documentation is
>
silent on this.
Lots of classes override isEqual. NSString for example.
>
3) isEqual: exists as a 'hook' to customize the way (mostly)
>
collection classes such as NSArray and NSDictionary handle objects.
<snip>
>
My question is: won't this trip up any of the internal workings of
>
Cocoa?
>
Suppose 'somewhere insyde' Cocoa relies on the default implementation
>
of
>
isEqual:?
If you use a category to a Cocoa class you might override a built in
implementation of isEqual. It's unlikely, but possible, that this would
interfere with the normal operations of that class.
A safe solution to that problem would be to create a simple wrapper
object that has a NSURLRequest as an instance variable. Then implement
isEqual in your wrapper object, in the same way as you did in your
category.
Also make sure you comply with this piece of documentation:
======================================================
If two objects are equal, they must have the same hash value. This last
point is particularly important if you define isEqual: in a subclass
and intend to put instances of that subclass into a collection. Make
sure you also define hash in your subclass.
======================================================
j o a r
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.