Skip to main content
added 289 characters in body
Source Link
gnasher729
  • 49.4k
  • 4
  • 71
  • 137

You are completely missing the point. If I change the width of a rectangle then the height is unchanged. Your square class breaks that.

As long as you are aware of the LSP violation, feel free to make square a subclass of rect. Change the implementation of setWidth and setHeight to assert(). If you like add a method setWidthAndHeight() which asserts if the result is not a square. Use what you can from the base class.

You are completely missing the point. If I change the width of a rectangle then the height is unchanged. Your square class breaks that.

You are completely missing the point. If I change the width of a rectangle then the height is unchanged. Your square class breaks that.

As long as you are aware of the LSP violation, feel free to make square a subclass of rect. Change the implementation of setWidth and setHeight to assert(). If you like add a method setWidthAndHeight() which asserts if the result is not a square. Use what you can from the base class.

Source Link
gnasher729
  • 49.4k
  • 4
  • 71
  • 137

You are completely missing the point. If I change the width of a rectangle then the height is unchanged. Your square class breaks that.