• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Wisdom of overriding isEqual:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wisdom of overriding isEqual:


  • Subject: Re: Wisdom of overriding isEqual:
  • From: Wade Tregaskis <email@hidden>
  • Date: Thu, 11 Mar 2004 00:46:28 +1100

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.

So long as your overrided isEqual does perform that task, comparing equality, it should not interfere with any normal operation. Any problems that arise would be bugs in Apple's code; i.e. dependencies on undocumented and undefined behaviour, which of course is the first thing you learn not to do in any OO programming course.

This goes for most methods, but is not a rule. You need to be aware of any complex interactions between classes - e.g. trying to override NSResponder methods, or something from NSApplication, or whatever else, would be very difficult to do properly, as each method performs various functions, many of which may be completely transparent to you as an API user.*

For isEqual, the required behaviour is about as simple as you can get, so there's no room for error (aside from the possibility that your overrided version doesn't compare equality properly, but that is of course a given). Override to your hearts content. :)

Wade Tregaskis
-- Sed quis custodiet ipsos custodes?

* = I can say from my experience subclassing NSSocketPort and overriding it's various methods that this can be a real nightmare.
_______________________________________________
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.


References: 
 >Wisdom of overriding isEqual: (From: Patrick Machielse <email@hidden>)
 >Re: Wisdom of overriding isEqual: (From: j o a r <email@hidden>)

  • Prev by Date: Re: array with int
  • Next by Date: Cocoa console applications (daemons)
  • Previous by thread: Re: Wisdom of overriding isEqual:
  • Next by thread: Re: Wisdom of overriding isEqual:
  • Index(es):
    • Date
    • Thread