Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know what is in the CDP that Steve referenced but basically the Objective-C Class Cluster is a construct that supports implementing the abstract <a href="http://en.wikipedia.org/wiki/Factory_method_pattern" rel="noreferrer">Factory</a> pattern.</p> <p><strong>The <em>idea</em> is simple</strong>: You want to provide a Factory (Cluster) interface that, with minimal description, manufactures and returns a specific concrete instance of a Factory Object that satisfies the behavior of the cluster family described by the Factory (Cluster) interface.</p> <p><strong>A simple concrete example</strong>: This example provides a Laugh factory that produces concrete classes of specific laughter types (e.g. Guffaw, Giggle). Pay attention to the <em>Laugh initWithLaughter:</em> method.</p> <p>In Laugh.h:</p> <pre><code>#define kLaughWithGuffaw 1 #define kLaughWithGiggle 2 @interface Laugh: NSObject {} - (Laugh *) initWithLaughter:(NSUInteger) laughterType; - (void) laugh; @end </code></pre> <p>In Laugh.m:</p> <pre><code>@interface Guffaws:Laugh {} - (void) laugh; @end @interface Giggles:Laugh {} - (void) laugh; @end @implementation Laugh - (Laugh *) initWithLaughter:(NSUInteger) laugherType { id instanceReturn=nil; ; // Removed for ARC [self release] if ( laughterType == kLaughWithGuffaw ) instanceReturn = [[Guffaws alloc]init]; else if( laughterType == kLaughWithGiggle ) instanceReturn = [[Giggles alloc]init]; else ; // deal with this return instanceReturn; } - (void) laugh { NSLog(@"Humbug"); } @end @implementation Guffaws - (void) laugh { NSLog(@"OH HA HA HOWAH HA HA HA"); } @end @implementation Giggles - (void) laugh { NSLog(@"Tee hee"); } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload