swlaschin / DomainModelingMadeFunctional

Extended code samples related to the book "Domain Modeling Made Functional". Buy the book here: https://pragprog.com/book/swdddf/domain-modeling-made-functional or here https://fsharpforfunandprofit.com/books/
Apache License 2.0
438 stars 84 forks source link

How to read CheckedAddress from a data store #19

Open eriklagerholm opened 2 years ago

eriklagerholm commented 2 years ago

Hello @swlaschin ! I know you are not maintaining this repo but I will try this anyways, who knows right? I have an implementation question that I have not been able to find the answer to. I'm currently trying to implement some of the ideas from the book in a Kotlin project, so there may be some language barriers.

But, in the book there is a service (function) that creates a CheckedAddress type. This type is private to the service and may only be created there so as to enforce invariants. I like this pattern a lot. But, when the construction of the type is so limited, how would you approach creating a CheckedAddress type from a data store? It would be nice to not have to open a back door in the domain, but that is what I have resorted to. Some languages and frameworks may offer instantiation of such types through reflection, but I haven't seen any such feature readily available in the Kotlin/Spring JPA world. I'm curious though what your thoughts on this subject would be.

Thank you for a great book and possibly for your answer to this long shot question.

//Erik