Software DevelopmentIntermediate 2 to 3 hours

Replace Inheritance with Composition

Fix a fragile class hierarchy that has grown out of control.

The Scenario

A game backend uses deep Object-Oriented inheritance: `class FlyingSwimmingEnemy extends SwimmingEnemy extends Enemy`. Now, the designers want a `FlyingSwimmingShootingEnemy`. The inheritance tree is breaking down.

The Brief

Refactor the class hierarchy to use Composition over Inheritance. Create separate behaviors (e.g., `canFly`, `canSwim`, `canShoot`) and compose them into the final entity.

Deliverables

  • The refactored code showing the behaviors (traits/mixins/interfaces) and the composed entity
  • An explanation of why the "Gorilla Banana" problem (fragile base class) makes deep inheritance dangerous

Submission Guidance

Use modern syntax (e.g., JavaScript factory functions, or TypeScript interfaces/mixins). The goal is flat architecture, not deep trees.

Submit Your Work

Your submission is graded against the rubric on the right. If you pass, you get a public Badge URL you can share on LinkedIn. There is no draft save, so work offline first and paste your finished response here.

This appears on your public Badge.

0/20000 charactersMarkdown supported

One per line or comma separated. Up to 5 links.

By submitting, you agree your submission text, name, and evaluation will appear on a public Badge URL.