The Primordial Command
Encapsulating absolute will as a tangible, executed artifact.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Enchantment // Binding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// C PATTERN //
#include <stdio.h>
#include <stdlib.h>
typedef struct Command Command;
struct Command {
void (*execute)(Command* self);
void (*undo)(Command* self);
};
// Concrete Command Data
typedef struct {
Command base;
int portal_id;
} OpenPortalCommand;
void execute_portal(Command* self) {
OpenPortalCommand* cmd = (OpenPortalCommand*)self;
printf("Portal %d opened.\n", cmd->portal_id);
}
void undo_portal(Command* self) {
OpenPortalCommand* cmd = (OpenPortalCommand*)self;
printf("Portal %d closed.\n", cmd->portal_id);
}
Command* create_portal_command(int id) {
OpenPortalCommand* cmd = malloc(sizeof(OpenPortalCommand));
cmd->base.execute = execute_portal;
cmd->base.undo = undo_portal;
cmd->portal_id = id;
return (Command*)cmd;
}
int main() {
Command* cmd = create_portal_command(404);
cmd->execute(cmd);
// Wait for conditions...
cmd->undo(cmd);
free(cmd);
return 0;
}
The Primordial Command traps an invocation within an impenetrable vessel. An instruction to alter reality is constructed, suspended, and then executed or inverted at precisely the required celestial cycle. It detaches the invoker from the exact execution logic.
Runic Tags:
#c
#behavioral
#command
#execution