Briefle words · Code & architecture
Composition over inheritance
Building objects by combining small parts they 'have', rather than stacking up parent classes they 'are'.
Say it to an AI
TypeScript Enemy model for a shoot-'em-up using composition over inheritance: one Enemy class that takes a movement and a list of abilities behind a shared Ability interface (strategy pattern). No subclasses per combination like FlyingShooterEnemy.
How an expert would brief the stronger version of “Game enemies”.
See it
Try it as a puzzle →A mobile shoot-'em-up models enemies that walk or fly and can shoot or heal.
Why: B's 'new Enemy(new Fly(), [new Shoot(), new Heal()])' assembles a medic; A needs the class 'HealerShooterFlyingEnemy'.
Related words
Room 3 · Functions & structure
Learn “Composition over inheritance” in a five-minute lesson