IT lexicon › Programming › Subclass sandbox

Subclass sandbox

Programming På svenska → Updated: 2026-10-26

A base class that hands out a toolbox and makes every subclass build its behaviour from those tools alone.

The base class declares one abstract method, typically activate(), plus a set of protected helpers: play a sound, spawn particles, move the player. Each subclass — a superpower, an enemy attack — implements its one method and calls only the helpers. All coupling to the rest of the engine lives in one place; when the audio system changes, you edit the base class, not a hundred subclasses.

Robert Nystrom named the pattern in Game Programming Patterns (2014). Its risk is the classic one with inheritance: the base class bloats until it does everything. Nystrom's own advice is to move clusters of helpers out into their own objects when that happens — or graduate to components.

← Back to the lexicon