The State
Altering a construct's behavior when its internal elemental state changes.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Subschool: Elementalism
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OBJC PATTERN //
@protocol TKElementalState <NSObject>
- (void)attack;
@end
@interface TKElemental : NSObject
@property (nonatomic, strong) id<TKElementalState> currentState;
- (void)attack;
@end
@implementation TKElemental
- (void)attack { [self.currentState attack]; }
@end
@interface TKFireState : NSObject <TKElementalState>
@end
@implementation TKFireState
- (void)attack { NSLog(@"Unleashes a torrent of fire!"); }
@end
The State pattern allows a construct to seemingly change its class at runtime by mutating its internal state strategy, seamlessly shifting from fire to ice.
Runic Tags:
#objc
#state
#behavioral