☕ JAVA CATHEDRAL DIFFICULTY: Adept Behavioral

The Encapsulated Command

Freezing a spell into a tangible object for queuing, logging, and undoing.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Transmutation // Reification
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JAVA PATTERN //
public interface HolyOrder {
    void execute();
    void undo();
}

public class ExcommunicationTarget {
    public void banish() { System.out.println("Target banished to the Null Void."); }
    public void restore() { System.out.println("Target restored to the classpath."); }
}

public class ExcommunicateCommand implements HolyOrder {
    private final ExcommunicationTarget target;

    public ExcommunicateCommand(ExcommunicationTarget target) {
        this.target = target;
    }

    @Override
    public void execute() {
        target.banish();
    }

    @Override
    public void undo() {
        target.restore();
    }
}

public class TribunalInvoker {
    private HolyOrder lastOrder;

    public void submitOrder(HolyOrder order) {
        this.lastOrder = order;
        order.execute();
    }

    public void rollback() {
        if (lastOrder != null) {
            lastOrder.undo();
        }
    }
}

In the volatile data-streams of the Sprawl, a request cannot merely be an ephemeral method call. The Cathedral demands a trail. The Command pattern captures the essence of a method invocation, binding its target and arguments into an immutable HolyOrder object.

By turning the act of invocation into an object, the TribunalInvoker can queue these orders in a transaction log, execute them at leisure, and most critically—invoke their undo() methods. This reification of action allows the high clerics to roll back disastrous enterprise decrees as if turning back time itself.

Runic Tags: #command #queuing #undo #enterprise