The State of the Possessed Machine
Allowing an object to alter its behavior entirely when its internal demonic possession changes.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Necromancy // Corp-mancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// COBOL PATTERN //
IDENTIFICATION DIVISION.
CLASS-ID. POSSESSED-TERMINAL INHERITS BASE-OBJECT.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS BASE-OBJECT IS "System.Object"
CLASS I-STATE IS "IState"
CLASS DORMANT-STATE IS "DormantState".
OBJECT.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CURRENT-STATE OBJECT REFERENCE I-STATE.
PROCEDURE DIVISION.
IDENTIFICATION DIVISION.
METHOD-ID. NEW.
PROCEDURE DIVISION.
INVOKE DORMANT-STATE "NEW" RETURNING CURRENT-STATE.
END METHOD NEW.
IDENTIFICATION DIVISION.
METHOD-ID. SET-STATE.
DATA DIVISION.
LINKAGE SECTION.
01 NEW-STATE OBJECT REFERENCE I-STATE.
PROCEDURE DIVISION USING NEW-STATE.
SET CURRENT-STATE TO NEW-STATE.
END METHOD SET-STATE.
IDENTIFICATION DIVISION.
METHOD-ID. RECEIVE-INPUT.
DATA DIVISION.
LINKAGE SECTION.
01 USER-INPUT PIC X(50).
PROCEDURE DIVISION USING USER-INPUT.
* The behavior depends entirely on the current spirit inhabiting the machine
INVOKE CURRENT-STATE "HANDLE-INPUT" USING SELF USER-INPUT.
END METHOD RECEIVE-INPUT.
END OBJECT.
END CLASS POSSESSED-TERMINAL.
To the user, the terminal appears the same, but the entity within shifts constantly. The State pattern allows the context object to swap out the spirit currently possessing it. In a dormant state, it echoes keystrokes; in a frenzied state, it consumes the operator’s soul instead of printing to standard output.
Runic Tags:
#necromancy
#mainframe
#gof
#behavioral