4 ms·
Just curious, isn't it obvious from a logical standpoint? I don't see how one could consider a mutable type to be a subtype of an immutable one. On the other ha
by aatd86 4y ago
Just curious, isn't it obvious from a logical standpoint?
I don't see how one could consider a mutable type to be a subtype of an immutable one. On the other hand, an immutable subtype of a mutable one seem plausible?
- cogman10 4y agoImmutable from a mutable is just as implausible. You cannot remove a method from a subtype which results in mutating methods being disabled through other means (like throwing exceptions). This is also a violation of LSP and the open close principle. Consider a `List` with an `add` function. What would you do with that `add` function to make an `ImmutableList` subtype?
- aatd86 4y agoAh I see. Why throw exceptions? They could just be noop depending on the typestate? But still it doesn't look very nice in practice. I think that in that case, it does make much more sense for a mutable type to be a subtype of the immutable one. The immutable threw me off track. It's just that the supertype would lack mutation operations. (in a sense immutable would be the default for every type). Thank you.