3 ms·
The thing you've spotted is that a square is a "rectangle with constraints". A Fox is not an implementation of an Animal: it is an Animal with constraints (fur
by lowbloodsugar 6y ago
The thing you've spotted is that a square is a "rectangle with constraints". A Fox is not an implementation of an Animal: it is an Animal with constraints (fur = orange, tail = bushy, says = "what?"). An integer is not an implementation of a Real, it is a constrained set of specific reals.
Some programming languages do this. IIRC XML Schemas allow constraints of derived "types". Prolog, obv. Cyc, for sure.
In UML we talk about generalizations and specializations, a superclass is more general, a derived class is more specific. But specialized means "I do X in a specific way", as opposed to a new constraint like "You can't do X with me".
And this is where we get into the immutable object discussion, and note that if we had a Square class, then you couldn't change its height but you could say square.with_height(10) and it would return a rectangle.
Then, one wonders, if you had rectangle(10,5).with_height(10) would it return a square?! And suddenly we are in the world of "type" being utterly ephemeral and dependent only on the state of an object, and then we would only have free objects, while "Interfaces" or "Types" would actually be constraints, and a Square would be "a rectangle with two equal dimensions" and now we are writing Cyc Theorems.