There is a similar approach in the book "Domain Modeling Made
Functional" by Scott Wlaschin. Some examples from the book:
type CheckNumber =
CheckNumber of int
type CardNumber = CardNumber of string
type PaymentMethod =
| Cash
| Check of CheckNumber
| Card of CreditCardInfo
type PaymentAmount = PaymentAmount of decimal
type Currency = EUR | USD
type Payment = {
Amount: PaymentAmount
Currency: Currency
Method: PaymentMethod
}
(The solutions used in the book are intended for a type system like that of F# or OCaml, but but it looks like the same general concept as the Medium article.)
Unfortunately I didn't finish reading the book and haven't tried its examples in any real apps, so I can't speak to how well this works in practice, but it makes sense to me.
There's also a video by the author that I posted a while back:
https://www.youtube.com/watch?v=Up7LcbGZFuo
This reminds me the amount role in money transfer.https://medium.com/better-programming/why-you-should-avoid-using-primitive-types-cb55857baa39
--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to object-composit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/object-composition/b343828e-8b41-4b1c-91d7-658196e0e301o%40googlegroups.com.