HomeChallengesRepsProblemsLeaderboardTake a challenge

The subclass that broke its parent

A square is a rectangle. The code disagrees, and only a shared test shows why.

Advanced18 min on the clock4 graded checks · 100 pointsObjects That Behave
Graded by running your code against real cases.

What you build

  • Make setting the width leave the height alone, for every exported type
  • Give Square its own shape rather than inheriting a promise it cannot keep
  • Keep both usable through one contract
  • Keep totalArea working for both

Done means

The same expectations hold for every exported type, and both still total correctly.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.

  1. A Rectangle’s sides move independently+20Keeping the promises you inherit
  2. Nothing inherits a promise it cannot keep+35Keeping the promises you inherit
  3. Square keeps the promises it does make+25Keeping the promises you inherit
  4. Both still work through one contract+20Keeping the promises you inherit

What it teaches

Keeping the promises you inheritadvanced

Anywhere the parent works the child must work too — and a subclass that compiles perfectly can still break the first caller who relied on something the parent quietly promised.

The rest of Objects That Behave