• 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: Best pattern for similar objects with differences
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Best pattern for similar objects with differences (From: Paul Bruneau <email@hidden>)

  • Prev by Date: Re: NSPopUpButton, Bindings & separator items
  • Next by Date: [fixed]Re: Don't highlight button's text when clicked
  • Previous by thread: Re: Best pattern for similar objects with differences
  • Next by thread: Re: Best pattern for similar objects with differences
  • Index(es):
    • Date
    • Thread