Re:Ask HN: What topics/subjects are worth learning for a new...
by Aeolun on Sunday September 16, 2018 @06:12PM
(#18001487)
Ah, I just see if people realize that Square is a subclass of Rectangle.
[ Parent
| on HN ]
Re:Ask HN: What topics/subjects are worth learning for a new...
by Zalastax on Sunday September 16, 2018 @06:20PM
(#18001545)
But is it though? If your objects are immutable I agree but if you have setHeight and setWidth I don't.
Re:Ask HN: What topics/subjects are worth learning for a new...
by Aeolun on Tuesday September 18, 2018 @10:09AM
(#18015435)
If you have set width and height, then you don’t need the Square class at all.
Re:Ask HN: What topics/subjects are worth learning for a new...
by jonny_eh on Monday September 17, 2018 @02:49AM
(#18003727)
It can be mutable if setHeight sets width automatically, and vice-versa.
Re:Ask HN: What topics/subjects are worth learning for a new...
by Jare on Monday September 17, 2018 @05:11AM
(#18004278)
This 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.
Re:Ask HN: What topics/subjects are worth learning for a new...
by zild3d on Monday September 17, 2018 @12:06PM
(#18007177)
> 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