• 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
Class Clusters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Class Clusters


  • Subject: Class Clusters
  • From: Drew McCormack <email@hidden>
  • Date: Tue, 20 May 2003 12:56:51 +0200

I am trying to write a simple class cluster, but have come up against a problem. My basic design is this:

DataSet
-init (returns a InMemoryDataSet)
-initWithData (returns InMemoryDataSet)
-initWithFileHandle (returns FileHandleDataSet)

FileHandleDataSet : DataSet
-initWithFileHandle

InMemoryDataSet : DataSet
-initWithData

DataSet is the public abstract base class to the other two.
If the initWithData method of DataSet gets called, it tries to create an InMemoryDataSet object and return that in its place. To do this it calls the "initWithData" method of InMemoryDataSet. But the initWithData method of InMemoryDataSet needs to initialize its superclass by calling init, ie,

-(id)initWithData:(NSData *)data {
self = [super init];
return self;
}

This calls the init method of DataSet, which is also designed to create and return a InMemoryDataSet, creating an infinite loop.
How should this be avoided? Should I just check the class of the sender in the init method of DataSet to determine my course of action, or is there a better way?

ie.

-(id)init {
if ( [[self class] isEqual:[DataSet class]] ) {
[self release];
self = [[InMemoryDataSet alloc] initWithData:nil];
}
else {
self = [super init];
}
return self;
}

Drew

========================================
Dr. Drew McCormack (Kmr. R153)
Afd. Theoretische Chemie
Faculteit Exacte Wetenschappen
Vrije Universiteit Amsterdam
De Boelelaan 1083
1081 HV Amsterdam
The Netherlands

Email email@hidden
Telephone +31 20 44 47623
Mobile +31 6 483 21307
Fax +31 20 44 47629
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Class Clusters
      • From: John Anderson <email@hidden>
  • Prev by Date: Making Drawers
  • Next by Date: Re: the art of #includes
  • Previous by thread: Making Drawers
  • Next by thread: Re: Class Clusters
  • Index(es):
    • Date
    • Thread