Composition over Inheritance

Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.

The problem

  • hard
  • Pro

A game has a class hierarchy: Character, then Flying Character and Swimming Character, and now designers want a duck that both flies and swims. Explain why the inheritance tree struggles with this, and how you'd redesign it using composition.

Talk this problem through with an AI coach

This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.

Start free →