4 ms·
they said "an order cannot ever have DeliveryDetails" so, if in a nominative subtyping situation like you suggest, a DeliveredOrder is-a Order, and so we can s
by hnbroseph 8y ago
they said "an order cannot ever have DeliveryDetails"
so, if in a nominative subtyping situation like you suggest, a DeliveredOrder is-a Order, and so we can see that some subset of Orders CAN have DeliveryDetails. any method receiving an Order could receive a DeliveredOrder.
- contravariant 8y ago> any method receiving an Order could receive a DeliveredOrder. This seems reasonable, if not outright desirable.
- hnbroseph 8y agoperhaps, perhaps not. in the abstract there's no way to valuate it. it depends on what it means to be an Order and what it means to be a DeliveredOrder, what assumptions are made by code that receives an Order, etc.
- tigershark 8y agoNo, most of the time is wrong. If you have a DeliveredOrder you want to make sure that is not delivered again, so the delivery function should accept only an Order, not a DeliveredOrder. If in some different system you need a domain object that is both an Order and a DeliveredOrder than in F# you simply use an union type: type Order = UndeliveredOrder of UndeliveredOrder | DeliveredOrder of DeliveredOrder And in this way you can write a function that accepts both an UndeliveredOrder and a DeliveredOrder.