• 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: Mutable classes and class clusters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mutable classes and class clusters


  • Subject: Re: Mutable classes and class clusters
  • From: Chris Kane <email@hidden>
  • Date: Sun, 16 Sep 2001 14:50:18 -0700

On Saturday, September 15, 2001, at 12:48 PM, Rob Rix wrote:
2) One of the classes I'm implementing in my framework is about to be redesigned as a class cluster, with a single public class (unless I find that separating it into mutable and immutable would be worthwhile, of course). So, to make a class cluster, is all that is involved changing my class' -(id)init method so that it returns an instance of a private subclass?

Or instead of allocating an object only to have it deallocated in -init, override +allocWithZone: to allocate an instance of the appropriate concrete class.

+ (id)allocWithZone:(NSZone *)zone {
if ([MyAbstractClass self] == self)
return NSAllocateObject([MyConcreteClass self], 0, zone);
return [super allocWithZone:zone];
}

Then the -init method will go right to an instance of the concrete class. This works well when for any particular abstract class you know which concrete class to use (ie, there is a one-to-one correspondence). If you don't know which class you'll need until the init method is called, or otherwise don't have enough information at +allocWithZone: time to allocate the real object, then going through a placeholder singleton object (returning that from the +allocWithZone:) is an efficient way to go. Peter Ammon <email@hidden> talked about this in another email.


Chris Kane
Cocoa Frameworks, Apple


References: 
 >Mutable classes and class clusters (From: Rob Rix <email@hidden>)

  • Prev by Date: Re: A first stab at a schema (possible names)
  • Next by Date: Re: Following focus and scrolling controls into view
  • Previous by thread: Re: Mutable classes and class clusters
  • Next by thread: Problems with NSUnarchiver (Java)
  • Index(es):
    • Date
    • Thread