Best pattern for similar objects with differences
Best pattern for similar objects with differences
- Subject: Best pattern for similar objects with differences
- From: Paul Bruneau <email@hidden>
- Date: Wed, 4 Nov 2009 13:47:01 -0500
Hi-
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.
This means that if you choose a door type, many properties that are
only used by any of the other types will go unused. On the other hand,
it's very good for if the user wants to change the door type--the
properties are all there ready and waiting.
But I did have the idea that I should make SLDoor a superclass of new
classes, one for each type of door. So I would have an SLFlushDoor,
an SLMonumentalDoor, and an SLPlankDoor for example, all subclasses of
SLDoor.
In this way, I can really separate out all kinds of code and
properties that are specific to a certain type of door, while keeping
in the superclass all the properties that are shared among several or
all of the types of door (I'm going to have categories to handle
drawing, material takeoff, pricing, etc for each door type).
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 (and possibly back again) with anything close to the
ease that I currently do it with the doorType property (but I shudder
to think of all the if() statements I would have strewn through all my
code if I stick with this pattern.)
Thank you
_______________________________________________
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