4 ms·
But is it though? If your objects are immutable I agree but if you have setHeight and setWidth I don't.
by Zalastax 8y ago
But is it though? If your objects are immutable I agree but if you have setHeight and setWidth I don't.
- jonny_eh 8y agoIt can be mutable if setHeight sets width automatically, and vice-versa.
- Jare 8y agoThis is a terrible idea. A rectangle by definition has width and height independent of each other. A square does not fit that description and thus is not a rectangle. Even if you did something like implementing the square's size as an average of the underlying rectangle's width and height, which would apparently support both classes correctly, you will get in trouble with the semantics or with other, less "fakeable" properties of these objects.
- zild3d 8y ago> A rectangle by definition has width and height independent of each other. That's not really true though. Definition is a quadrilateral w/ 4 right angles. Width and height can be dependent or not
- jonny_eh 8y agoI've never come across this definition. I've always heard that squares are a subset of rectangles, just as rectangles are a subset of parallelograms.
- Aeolun 8y agoIf you have set width and height, then you don’t need the Square class at all.