• 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: Convenience Methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Convenience Methods
      • From: Greg Titus <email@hidden>
  • Prev by Date: RE: Convenience Methods
  • Next by Date: Re: Convenience Methods
  • Previous by thread: Re: Convenience Methods
  • Next by thread: Re: Convenience Methods
  • Index(es):
    • Date
    • Thread