Re:Inheritance Is Terrible
by thomasahle on Saturday March 19, 2016 @05:55PM
(#11320660)
Would you also support Shape > Rectangle > Square?
Or are all your super classes abstract?
[ Parent
| on HN ]
Re:Inheritance Is Terrible
by Bluestrike2 on Saturday March 19, 2016 @08:21PM
(#11321175)
If we're being cheeky, a square is also a rectangle. Unless I'm misreading your post, I'd expect your superclasses to be as abstract as they needs to be and no more:
Vehicle < Car, Truck, etc.
Person < Employee, Customer, etc.
There's a pretty obvious logic to them that doesn't really demand much extra thought. I can't think of anyone outside of an irreverent ontologist who would suggest going beyond that unless there's a valid reason for it, like say: PhilosophicalBeing < Person < Employee, Customer, etc.A mutable square is not a mutable rectangle, because a mutablr rectangle can change its width independently of its length. This is the classic problem of contravariance: subtyping in the face of mutability.
Re:Inheritance Is Terrible
by Bluestrike2 on Sunday March 20, 2016 @01:56AM
(#11321973)
Good point. Without giving it much if any thought, I made an assumption--that the square is immutable--that probably wouldn't even be accurate in this context. In fact, it's the usual example used to talk about substitutability. Oops.