The Command
Encapsulating a spell cast as an object for later execution.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Evocation // Subschool: Encapsulation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OBJC PATTERN //
@protocol TKIncantation <NSObject>
- (void)execute;
@end
@interface TKTeleportIncantation : NSObject <TKIncantation>
@property (nonatomic, strong) NSString *destination;
- (instancetype)initWithDestination:(NSString *)dest;
@end
@implementation TKTeleportIncantation
- (instancetype)initWithDestination:(NSString *)dest {
if (self = [super init]) { _destination = dest; }
return self;
}
- (void)execute { NSLog(@"Teleporting to %@", self.destination); }
@end
Command captures the very essence of a spell inside an object, permitting undo operations, queuing, and macro spells through NSInvocation or blocks.
Runic Tags:
#objc
#command
#behavioral