Skip to content

Latest commit

 

History

History
executable file
·
15 lines (11 loc) · 676 Bytes

937d.md

File metadata and controls

executable file
·
15 lines (11 loc) · 676 Bytes

Back to questions

937d: Flawed rectangle

The class below models a rectangle shape, which has a particular area. For the purposes of this question, the inheritance hierarchy that Rectangle is part of is not important. Can you detect a design flaw in the class? Explain what the problem is, and present a better version of the class that fixes the problem.

Hint: this class should enforce an important invariant that you should identify. How does the fact that width, height and area can all be modified allow this invariant to be broken?