The Factory Method
Defer instantiation to subclasses relying on the NSObject lineage.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Subschool: Evocation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OBJC PATTERN //
@protocol TKFamiliar <NSObject>
- (void)speak;
@end
@interface TKSummoner : NSObject
- (id<TKFamiliar>)summonFamiliar; // The Factory Method
@end
@implementation TKSummoner
- (id<TKFamiliar>)summonFamiliar {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Subclasses must override" userInfo:nil];
}
@end
The Factory Method leverages the dynamic nature of NeXTSTEP’s runtime. It binds familiar spirits by deferring exact class summoning until runtime.
Runic Tags:
#objc
#factory-method
#creational