In accordance with this issue of stack overflow in the DDD architecture, the βhelperβ classes can be in different layers depending on their purpose. For example, an assistant who formats something in a friendly way enters the user interface. The database assistant will go to the infrastructure.
But what about helpers that can be used by more than one layer? For example, the calculation of age. Age may be required at the level of the business logic model. It is used by several objects, so it should not be in a specific object. There are also places where age is only required for display in the user interface. Similarly, I have string functions that can be used by more than one layer. For example, my user methods Right and Left can be used for formatting in the user interface, but they can also be used in the model, for example, prefix-based conditional logic.
So where do these general methods go? My setup is this:
- interface
- Application
- Model
- Infrastructure
The model is basic and does not depend on the infrastructure, so general assistants cannot work in the infrastructure. I am considering two options:
1) You have another layer called Common or similar, which can be used by any layer. This would create a dependency between Model and Common.
2) Duplicate the auxiliary logic in any layer. For example, have an age assistant in the user interface and have an age assistant in the model. This will violate DRY, but will not require the domain to be dependent on a "common" level.
Which option is better? Is it good for the model layer to be dependent on the "general" level?
UPDATE:
For 2.5 years since this question was asked, I concluded:
- Things like Right, Left, etc., which compensate for limitations in the structure, belong to the "Common" utilities / auxiliary component, which the Model / Domain level depends on.
- The General Utility / Assistant component does not have to be very large. Having more experience, I found that many of the things that I thought of as assistants really apply to the domain model.
- Age belongs to its own class in the domain layer. Like things like address, phone number and money, I see these things as objects of value. Understanding value objects was really key to my understanding of creating reusable domain classes that could be included in other classes.
source share