A Game Design Document describes what the game is. This page describes how the code is shaped to support it. The patterns below are the common architectural building blocks of game engines and gameplay code: ways to decouple systems, sequence frame work, model behavior, and squeeze out performance.
These are own-words summaries focused on intent, when to reach for it, and the trade-off you accept. They are not a substitute for the source material.
Wrap an action in an object so it can be stored, queued, undone, or replayed. The caller fires a command without knowing what it does; the command knows how to do and undo it.
Use when: input remapping, undo/redo, AI issuing the same actions as a player, recording/replaying input, networked input streams.
Trade-off: one object per action adds indirection and allocation; pool or flyweight commands if they are hot.
Share the data that is identical across many instances; keep only the per-instance data local. A thousand trees reference one shared mesh/texture and carry only their own transform.
Use when: huge counts of near-identical entities (foliage, tiles, particles, mobs).
Trade-off: the shared state must be immutable; mutation leaks across every user of the flyweight.
Let objects announce events without knowing who listens. Subjects publish; observers subscribe. Decouples the thing that changes from the things that react.
Use when: achievements, UI reacting to gameplay, analytics, loosely coupled cross-system notifications.
Trade-off: implicit control flow is hard to trace; dangling observers leak. Prefer an explicit event queue for high-volume or ordered events.
Render or compute into a back buffer, then swap it with the front buffer atomically. Readers always see a complete, consistent frame; writers never tear.
Use when: rendering, any state where a half-updated read is visible/wrong (e.g. cellular automata, simultaneous-turn resolution).
Trade-off: double the memory for the buffered state; the swap must be cheap and atomic.
Encode behavior as data — instructions for a tiny virtual machine — instead of hardcoding it in the engine language. Designers/modders author behavior without recompiling.
Use when: spell/skill scripting, modding surfaces, sandboxed user content, data-driven content at volume.
Trade-off: you are building (and debugging) a VM and toolchain; heavy upfront cost. AngelScript/Lua often fill this role off-the-shelf.
Move what would be subclasses into data instances of a single “type” class. A Monster holds a reference to a MonsterType (“Dragon”, “Goblin”) that carries shared stats/behavior.
Use when: content defined by designers in data; new “kinds” should not require new code.
Trade-off: less compile-time type safety; behavior differences beyond data still need code.
Build an entity by composing independent components (position, render, physics, health) instead of one deep inheritance tree. The entity is a bag of parts.
Use when: entities that mix and match capabilities; the foundation of ECS.
Trade-off: cross-component communication needs a discipline (messages, shared data, or systems) or it becomes spaghetti.
Lay out data so the CPU cache stays hot: contiguous arrays of the data a loop actually touches, processed in order. The single biggest real-world game perf lever.
Use when: hot loops over many entities; the core motivation behind ECS / struct-of-arrays.
Trade-off: less flexible, less object-oriented layout; harder to mutate structure at runtime.
Defer expensive recomputation until the result is actually needed, and skip it entirely when nothing changed. Mark dirty on write; recompute lazily on read.
Use when: derived data that is costly to compute and changes less often than it is read (world transforms, baked lighting, derived stats).
Trade-off: correctness hinges on every mutation setting the flag; a missed set is a silent stale-data bug.
Design Patterns: Elements of Reusable Object-Oriented Software — the Gang of Four (origin of Command, Flyweight, Observer, Prototype, Singleton, State).
Unity DOTS / ECS docs — Data Locality and Component patterns in a production engine.