🍏 OBJ-C RUNES DIFFICULTY: Apprentice Behavioral

The Strategy

Interchanging arcane algorithms dynamically.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Divination // Subschool: Tactics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OBJC PATTERN //
@protocol TKCombatStrategy <NSObject>
- (void)executeTactics;
@end

@interface TKWarlord : NSObject
@property (nonatomic, strong) id<TKCombatStrategy> strategy;
- (void)engage;
@end
@implementation TKWarlord
- (void)engage { [self.strategy executeTactics]; }
@end

@interface TKStealthStrategy : NSObject <TKCombatStrategy>
@end
@implementation TKStealthStrategy
- (void)executeTactics { NSLog(@"Attacking from the shadows."); }
@end

Strategy isolates the varied tactics of battle from the warlords that invoke them. Strategies can be hot-swapped during combat via message passing.

Runic Tags: #objc #strategy #behavioral