• 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: make class cluster
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make class cluster


  • Subject: Re: make class cluster
  • From: Mike Abdullah <email@hidden>
  • Date: Sun, 7 Oct 2007 16:15:29 +0100


On 6 Oct 2007, at 13:10, Hans van der Meer wrote:

I am uncertain how to construct a class-cluster and cannot find all I should know in the ObjC and Cocoa guides (the montharray example in the latter is kind of special). Let me describe the setup I have in mind.

Two classes are to be made, having many methods in common but differing in the init method and how they produce their result. Hence the idea of making a class-cluster.

The idea is now:

1. The class-cluster class is merely a dispatcher of the worker classes.
2. Each of the three classes (cluster class and two work classes) descends directly from NSObject and thus they are independent classes.
3. The cluster class is called with [[cluster-class alloc] init...] and dispatches a work class by returning [[work-class alloc] init...]


Questions I could not satisfactorily answer myself:

1. Is the setup of three independent classes correct or should I make the two work classes a subclass of the cluster class? The common code can then be shared through the cluster class.

Firstly, let's clarify the terminology here a little. In the case of a class cluster, you have the "abstract" class (not "cluster"), and then any number of "concrete" subclasses/implementations.


So, to answer the original question; by definition, your concrete implementations should be subclasses of the abstract class. a) because this allows you to share common code, and b) because it ensures there is a consistent API across the classes, keeping the compiler happy.


2. In the sequence [[cluster-class alloc] init...] should I release self? Thus in the cluster-class as init for the production of a work class:
- (id) init... {
[self release]; // needed??? too early at this point???
id worker = [[worker alloc] init...];
return worker;
}

You should indeed release self otherwise this could turn into a rather large memory leak. It's much the same as Apple's advice for when there is an error instantiating a class - the init method should [self release] and then return nil.

I would appreciate your expert insight. Thanks in advance.

Hans van der Meer



_______________________________________________

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:
40mikeabdullah.net


This email sent to email@hidden

_______________________________________________

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: 
 >make class cluster (From: Hans van der Meer <email@hidden>)

  • Prev by Date: timeZoneView
  • Next by Date: Re: NSButton
  • Previous by thread: Re: make class cluster
  • Next by thread: re: Convert NSOpenGLView pixel coordinates to OpenGL world coordinates
  • Index(es):
    • Date
    • Thread