RE: Convenience Methods
RE: Convenience Methods
- Subject: RE: Convenience Methods
- From: Jeff Laing <email@hidden>
- Date: Thu, 27 Sep 2007 09:59:04 +1000
> > Sometimes when I'm writing convenience constructors I might write
> >
> > + (MyClass *)myClassWithFoo:(int)f
> > {
> > return [[[self alloc] initWithFoo:f] autorelease];
> > }
> >
> > where "self" is, of course, the class. A good reason to do that is
> > that it means that a subclass only has to override -initWithFoo: in
> > order to make +myClassWithFoo: work as expected.
>
> I'm still undecided on whether this is a good thing or not.
After my Dog's example, it occurred to me that my uneasiness was because of
an encapsulation thing again.
When you say "a subclass only has to override -initWithFoo:", how did you
*know* that the superclass had done the right thing in its myClassWithFoo: ?
Subclasses shouldn't depend on implementation detail in their superclasses,
should they?
If you wrote all the code then sure, you can be confident because you can
look at it. But speaking as someone who works on a development team that
works on *millions* of lines of code, I've gotten a lot more paranoid about
assuming things about "the other guy" making changes that he's sure won't
affect anyone...
_______________________________________________
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