RE: Convenience Methods
RE: Convenience Methods
- Subject: RE: Convenience Methods
- From: Jeff Laing <email@hidden>
- Date: Thu, 27 Sep 2007 12:51:12 +1000
Erik stepped back on this, but I had this typed up so here goes:
> On Sep 26, 2007, at 7:22 PM, Erik Buck wrote:
>
> > The following simple example illustrates the reality of writing an
> > algorithm that relies on a supposedly immutable object actually
> > being immutable.
>
> Contrived example. :)
Not so much contrived as dependent on the mistaken belief that
NSArray *widgetsArray = [testManager widgets];
returns a reference to the existing one, rather than a *new* array. The
documentation of [testManager widgets] sould presumably make clear that you
have the original array, not a copy and that calling removeWidget: will
alter it (breaking the rule that you aren't allowed to change an NSArray
while an NSEnumerator is running over it).
Perhaps it ties into Greg Titus's argument that you should never subclass
without knowing the full implementation detail of your superclass, but goes
one step worse and implies you should never use *any* class unless you know
its full implementation detail.
(ie, there is no guarantee that the testManager is implementing the
collection of widgets as an NSArray, it may be an NSDictionary which it
walks over to satisty the [... widgets] request - if you knew this detail,
you would never have assumed you had the original NSArray)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden