🍏 OBJ-C RUNES DIFFICULTY: Adept Structural

The Composite

Treating single constructs and their amalgamations uniformly.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Conjuration // Subschool: Swarm
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OBJC PATTERN //
@protocol TKGolem <NSObject>
- (void)awaken;
@end

@interface TKClayGolem : NSObject <TKGolem>
@end
@implementation TKClayGolem
- (void)awaken { NSLog(@"Clay golem stirs."); }
@end

@interface TKGolemLegion : NSObject <TKGolem>
@property (nonatomic, strong) NSMutableArray<id<TKGolem>> *golems;
- (void)addGolem:(id<TKGolem>)golem;
@end
@implementation TKGolemLegion
- (instancetype)init {
    if (self = [super init]) { _golems = [NSMutableArray array]; }
    return self;
}
- (void)addGolem:(id<TKGolem>)golem { [self.golems addObject:golem]; }
- (void)awaken {
    for (id<TKGolem> golem in self.golems) {
        [golem awaken];
    }
}
@end

The Composite creates nested hierarchies of golems, summoned identically whether they be solitary beasts or entire legions.

Runic Tags: #objc #composite #structural