Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> any method receiving an Order could receive a DeliveredOrder.

This seems reasonable, if not outright desirable.



No, 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.


perhaps, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: