• 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
Design Paterns: +/- Initializers and Subclassing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Design Paterns: +/- Initializers and Subclassing


  • Subject: Design Paterns: +/- Initializers and Subclassing
  • From: Christopher J Kemsley <email@hidden>
  • Date: Sun, 2 Aug 2009 22:17:06 -0700

Ok, so here's the deal:

I have a class (CYMethod) that provides a standard interface for multiple implementations of the same type (multiple ways in which to read a file, for instance). Here are its constructors:


+ (CYMethod*) method { return [ [ [CYMethod alloc] init ] autorelease ] ; } - (CYMethod*) init { if ( self = [super init] ) { } return self ; }


What I want to be able to do is subclass this, but only override the - init method. However, if I use the above code and call


[CYMethodSubclass method]

I'll get back a new instance of CYMethod, not CYMethodSubclass.


How do I make the +method call return an initialized object of whatever type the +method was sent to? (so that [CYMethodSubclass method] returns [ [ [CYMethodSubclass alloc] init ] autorelease])



Thanks, -Christopher _______________________________________________

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: Design Paterns: +/- Initializers and Subclassing
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Table view data source methods order?
  • Next by Date: Re: Design Paterns: +/- Initializers and Subclassing
  • Previous by thread: Fwd: Table view data source methods order?
  • Next by thread: Re: Design Paterns: +/- Initializers and Subclassing
  • Index(es):
    • Date
    • Thread