4 ms·
If you think OOP is particularly well-suited to domain modelling, you should try the FP approach to domain modelling. You will never be able to unsee the compl
by epgui 2y ago
If you think OOP is particularly well-suited to domain modelling, you should try the FP approach to domain modelling.
You will never be able to unsee the complexity inherent to OOP.
- jprete 2y agoDo you happen to have a link to an example or explanation?
- arendjr 2y agoThe keyword to search for is algebraic data types, which are common in functional languages, but for instance Rust also has them. Here is an example comparing C# with F#, where the latter also algebraic data types: https://blog.ploeh.dk/2016/11/28/easy-domain-modelling-with-types/ https://blog.ploeh.dk/2016/11/28/easy-domain-modelling-with-...
- neonsunset 2y agoThe syntax has improved quite substantially since 2016 for pattern matching at C#'s end, and it's very easy to model ADTs with records (and the experience of using them even before that was decent with methods accepting lambdas). Today, you write it in a similar way you would write a match in Rust.
- nequo 2y agoHow do you represent sum types in C# today? Can enum members hold records as data, or do you do it differently?
- epgui 2y agoThe other commenter is not technically wrong to point at “algebraic data types”, but I don’t think that answer is helpful at all. It’s like saying the answer to data modelling is tuples. I would instead recommend searching for “functional programming and domain driven design”.
- rapnie 2y agoDomain Modeling Made Functional [0] by Scott Wlaschin [0] https://www.youtube.com/watch?v=2JB1_e5wZmU https://www.youtube.com/watch?v=2JB1_e5wZmU
- brabel 2y agoYou can try the FP approach today in most languages that are not even FP: * Rust * Kotlin * Dart * Java Yep, even Java. Check this out: https://blog.jdriven.com/2021/10/sealed-classes/ https://blog.jdriven.com/2021/10/sealed-classes/