Modeling Simple Values
Let’s first look at the building blocks of a domain: simple values.
As we found out when we gathered the requirements, a domain expert does not generally think in terms of int and string but instead in terms of domain concepts such as OrderId and ProductCode. Furthermore, it’s important that OrderIds and ProductCodes don’t get mixed up. Just because they’re both represented by ints, say, doesn’t mean that they are interchangeable. So to make it clear that these types are distinct, we’ll create a “wrapper type”—a type that wraps the primitive representation.
As we mentioned earlier, the easiest way to create a wrapper type in F# is to create a “single-case” union type, a choice type with only one choice.
Here’s an example: ...
Get Domain Modeling Made Functional now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.