Re: Best pattern for similar objects with differences
Re: Best pattern for similar objects with differences
- Subject: Re: Best pattern for similar objects with differences
- From: Uli Kusterer <email@hidden>
- Date: Thu, 5 Nov 2009 16:25:23 +0100
On 04.11.2009, at 19:47, Paul Bruneau wrote:
I'm in early development of an app (non-core data, NSDocument app)
that will deal with a lot of doors. I have created a door object,
SLDoor, which currently contains all of the properties that might be
used by any of the several types of doors.
There is a doorType property which is what determines which of the
types of doors a particular instance is.
You're not saying what you're doing with these doors, which makes it
pretty pointless to suggest stuff, but a few short hints what to look
into:
- In general, a somethingType on a class is a warning sign. Subclasses
are intended to provide different behaviour transparently to the
caller. E.g. if you're modeling actual doors for use to navigate
between rooms in a game, somethingType is probably a bad idea.
- However, sometimes a somethingType is exactly the right thing to
use. E.g. if you're keeping a catalog of doors, you're not keeping
doors, you're keeping entries that refer to doors, and the type might
be better. You didn't give us enough information to say either way.
- There is a "pimpl" pattern ("private implementation") that you could
use. I.e. the object of the outer class looks like a "door" that does
everything, and contains an object of an internal class which it asks
to do the actual work, which knows the door type specific design. But
for doors, this sounds like over-enginnering things.
Just food for thought.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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