Skip to content

Subclass Sandbox

A pattern where the parent provides a safe extension API and children are restricted to implementing only within that boundary.

  • When extending skills or AI while protecting core rules.
  • When you want to control designer-facing extension points.
  • Base Class: provides a safe API
  • Hook: child implementation point
  • Subclass: extension implementation

The code below is a simplified Unity example based on the scenario described above.

public abstract class SkillBase
{
public void ExecuteSkill()
{
if (!CanExecute())
{
return;
}
ConsumeResource();
PlayCastAnimation();
ApplyEffect();
}
protected virtual bool CanExecute() => true;
protected virtual void ConsumeResource() { }
protected virtual void PlayCastAnimation() { }
protected abstract void ApplyEffect();
}
public sealed class FireballSkill : SkillBase
{
protected override void ApplyEffect()
{
// Spawn fireball projectile.
}
}
  • Only the API allowed by the parent is exposed, so extension code can be safely constrained.
  • It is useful when common rules such as cooldowns or resource costs must be enforced in the base class.
  • If the base class grows too large, extension flexibility can actually decrease.
  • If hook contracts are unclear, behavior consistency can break between subclasses.

This shows the flow where the parent template enforces common rules and the child implements only the hook.

Subclass Sandbox Flow