Briefle
LearnGlossaryPricing

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.

Study A · the weaker one
Study B · the stronger one

Why: B's 'new Enemy(new Fly(), [new Shoot(), new Heal()])' assembles a medic; A needs the class 'HealerShooterFlyingEnemy'.

Related words

  • Single responsibility principle
  • Flag argument
  • Side effect
  • Parameter object
  • Long parameter list
  • Named arguments
  • Options object
  • Utils file

Room 3 · Functions & structure

Learn “Composition over inheritance” in a five-minute lesson

Start free
AI can build almost anything. The bottleneck is saying what you want.
WordsPricingTermsPrivacyRefundsContact
© 2026 Briefle