Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • The code is not fine, Square violates the contract that Rectangle makes. Commented Aug 28, 2010 at 21:52
  • The code is fine. Nowhere does he violate any contract that Rectangle makes, as Rectangle makes no contract. The spec of Rectangle::SetWidth needs a guarantee like "does not change height". Of course, we often assume this, but I would contend that without that explicit spec, it is my code that is wrong (as is the other example code in other answers to this question). Commented Aug 28, 2010 at 22:12
  • A spec doesn't have to be explicit to be a spec. You can't make everything explicit. Commented Aug 28, 2010 at 22:15
  • I suppose not. And to be clear, I wouldn't want to use a Rectangle class that didn't have that guarantee. But the OP's code doesn't rely on any guarantee, he needs code like mine above to create the described inheritance bug. Commented Aug 28, 2010 at 22:34