This question already has an answer here:
Is there a way to use the existing features of object oriented programming languages to work around the square/rectangle problem?
Can a child be defined in terms of being a more restrictive subset of its parent class rather than being defined in terms of additional features?
I'm trying to reconcile the difference between object-oriented inheritance and a real-world taxonomy where each child type has FEWER traits than its parent. Inheritance is subtractive. In OO, inheritance is additive.
Suppose we have a class Person. A Person can either be a Customer, with billing info, or an Employee, assigned a department. Further an Employee can either be a Supervisor with direct reports, or a Worker with assignments.
Classical OO inheritance would have Worker/Supervisor inherit from Employee which inherits from Person, where each child class has more characteristics than its parent class.
In the real world, though, it's the reverse: A Mammal has lots of potential features, a Canine has a subset of those features, and a Beagle has an even smaller subset.
Another way to look at it, A quadrilateral can be any shape with four sides. A parallelogram is a quadrilateral with parallel sides. A rectangle is a parallelogram with 90 degree angles, and a square is a rectangle with equal sides.
If I were to model a real-world taxonomy using OO inheritance, how would it be done?
I could start with a parent Square, with a length, and its child be a Rectangle with a length and a height, etc., but this is unnatural given the domain. Is there a way to do Object-Oriented programming inheritance going the other way?