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: Jens Alfke <email@hidden>
- Date: Wed, 4 Nov 2009 12:50:26 -0800
On Nov 4, 2009, at 10:47 AM, Paul Bruneau wrote:
So this is very attractive, but I keep worrying about how I would
change a door from one type to another if I utilize these
subclasses. Any ideas the best pattern to use? I can't figure out
how I would take an existing object of say SLFlushDoor and convert
it to an SLMonumentalDoor
Do you need to change the type of an instance? Or can you replace it
with a new instance of the new type? I don't know the details of your
model, but the latter seems cleaner, and works well with subclassing.
For example, if you need to convert to SLMonumentalDoor, you can add a
method to SLDoor:
- (SLMonumentalDoor*) asMonumentalDoor;
which creates a new instance. (SLMonumentalDoor can override this to
return self, of course.)
—Jens_______________________________________________
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