Boring introduction:
I know - DDD is not a technology. As I see it, DDD is the creation of an omnipresent language with the owner of a product and its reflection in the code in such a simple and structured way that it is simply impossible to interpret or lose.
But here comes the paradox in the game - to get rid of the technical side of the application in the domain model, it becomes good technical - at least in terms of design.
The last time I tried to keep an eye on DDD, it ended with a whole logical interface outside the domain objects in the "magic" services around the world and an anemic domain model.
I learned a few new ninja tricks and am wondering if I can deal with Goliath this time.
Problem:
class store : aggregateRoot { products; addProduct(product){ if (new FreshSpecification.IsSatisfiedBy(product)) products.add(product); } } class product : entity { productType; date producedOn; } class productTypeValidityTerm : aggregateRoot { productType; days; }
FreshSpecification should indicate if the product does not smell. To do this, he must check the type of product, find the days on it, how long the product has been fresh, and compare it with producedOn . Good is simple.
But here a problem arises - productTypeValidityTerm and productType must be managed by the client. He should be able to freely add / modify them. Since I cannot directly switch from product to productTypeValidityTerm , I need to somehow request their productType .
Previously, I would create something like ProductService , which receives the necessary repositories through the constructor, query terms, executes some additional voodoo and returns a boolean value (taking the appropriate logic further from the object itself and scattering it, who knows where).
I thought it would be acceptable to do something like this:
addProduct(product, productTypeValidityTermRepository){...}
But then again - I could not compile a specification from several specifications under freely, which is one of their main advantages.
So - the question is where to do this? How to store information about terms?