Choose an abstract controller interface
An abstract controller interface is useful when the game needs to invoke different controller types through the same contract. Start with the working PlayerController, AIController, and UIController examples before choosing that contract.
The maintained tutorial game retains concrete controllers and calls their useful
operations directly. Cheryl does not require an AbstractController base class.
Identify the operation the caller needs
Controller role |
Persistent dependencies and state |
Per-update operation |
|---|---|---|
Player |
Its scoped action context and application-selected bindings. |
Read copied input and produce an actor command. |
AI |
Goals, behavior state, and any longer-lived world services it borrows. |
Observe actor/world state and time, then produce an actor command. |
UI |
Session, interface components, and retained scene/upload state. |
Coordinate input, widgets, and scene publication. |
Player and AI controllers share an actor-command result. A common actor-decision interface can make choosing or replacing that source useful. The UI controller coordinates a different result: the application’s interface and its published scene.
Make ownership and update order explicit
A small game can use this composition without another engine base class:
Owner |
Owns |
Borrows |
|---|---|---|
Game |
Player, world systems, controllers and UI owner. |
Runtime context. |
Player/AI controller |
Decision state and any input-context lease. |
Its target actor or a world observation. |
Formation |
Enemy storage and shared march timing. |
Any world services it observes. |
UI owner |
Sessions, HUD/menu components and scene publication. |
Game values supplied for presentation. |
References do not require shared ownership: keep each borrower within its target’s
lifetime. Construct ordinary dependency relationships first; initialize loaded
appearance and uploaders in init_platform(), then live UI in init_simulation().
The game can forward each lifecycle hook to its controllers from one place while
preserving those two execution owners.
An application-defined AbstractGameObject does not register itself with Cheryl.
The game still calls its operations. Choose one update path: read a controller’s
command, update its actor once, then update systems and presentation in the game’s
chosen order. A forwarding controller plus another direct actor update would
advance that actor twice. Reuse appearance/bounds for a bullet without requiring
all actor behavior on every world object.
Choose the smallest useful contract
Keep concrete calls when they express the game’s update order clearly. Introduce a shared interface when a concrete caller needs uniform invocation or replaceable behavior. For actor controllers, establish the observations and command result before choosing a virtual method signature. For UI coordination, preserve the session and publication lifecycle taught in Create a UIController.
The useful outcome is an interface the game can explain and use. A shared class name alone does not establish shared responsibilities.