🍏 OBJ-C RUNES DIFFICULTY: Adept Structural

The Decorator

Wrapping objects in layers of ethereal augmentation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Abjuration // Subschool: Warding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OBJC PATTERN //
@protocol TKSpell <NSObject>
- (void)cast;
@end

@interface TKBasicSpell : NSObject <TKSpell>
@end
@implementation TKBasicSpell
- (void)cast { NSLog(@"A simple spark."); }
@end

@interface TKSpellDecorator : NSObject <TKSpell>
@property (nonatomic, strong) id<TKSpell> baseSpell;
- (instancetype)initWithSpell:(id<TKSpell>)spell;
@end
@implementation TKSpellDecorator
- (instancetype)initWithSpell:(id<TKSpell>)spell {
    if (self = [super init]) { _baseSpell = spell; }
    return self;
}
- (void)cast { [self.baseSpell cast]; }
@end

@interface TKFireDecorator : TKSpellDecorator
@end
@implementation TKFireDecorator
- (void)cast {
    [super cast];
    NSLog(@"Wreathed in flames!");
}
@end

Decorator enables dynamic empowerment of basic spells, wrapping them in Objective-C subclasses that intercept messages and amplify their effects.

Runic Tags: #objc #decorator #structural