![infoq domain driven design infoq domain driven design](https://res.infoq.com/presentations/RESTful-SOA-DDD/en/slides/1.jpg)
Otherwise the invariants cannot be enforced.
![infoq domain driven design infoq domain driven design](https://res.infoq.com/articles/ddd-with-tlc/en/headerimage/ddd-with-tlc-h-1535156235979.jpeg)
When the root is created, it is necessary that all objects subject to invariants are created too. If it is not, there is a chance for the creation process to be half done for some objects, leaving them in an undefined state. When the root of the Aggregate is created, all the objects contained by the Aggregate are created along with it, and all the invariants are enforced.It is important for the creation process to be atomic. It would make use of the file infrastructure to retrieve the template from the disk.įactories are used to encapsulate the knowledge necessary for object creation, and they are especially useful to create Aggregates. This would be a service located in the domain layer. So we create a separate Service whose purpose is to retrieve a report template based on report's ID. It does not belong to the Template object either. It is not appropriate to put such an operation in the Report object itself. This template is stored in a file or in the database. Since reports are based on templates, a Service could be created, and its purpose would be to obtain the template which corresponds to a reportID. The domain layer is responsible for creating and returning the report being given its name. This name is passed through the application layer to the domain layer. But we will mention only the reportID for simplicity.
![infoq domain driven design infoq domain driven design](https://res.infoq.com/presentations/ddd-rest/en/slides/sl8.jpg)
Some other parameters are passed, like the items shown in the report and the time interval of the data included in the report. The infrastructure layer will support database access and file access.When a user selects a report to be created, he actually selects the name of the report from a list of names. Two of those objects are Report and Template, which the reports are based on. The domain layer will contain the core of the domain, objects directly related to the reports. It interacts with the database infrastructure during login operations, and interacts with the domain layer when it needs to create reports. The application layer is a thin layer which stands between the user interface, the domain and the infrastructure. The UI layer is incorporated in web pages and allows the user to login, to select the desired report and click a button to request it. The final result is an HTML page which is shown to the user in a web browser. The reports make use of data stored in a database, and they are generated based on templates. Let's consider a practical example, a web reporting application. If the operation is about domain objects, and is strictly related to the domain, serving a domain need, then it should belong to the domain layer. If the operation performed conceptually belongs to the application layer, then the Service should be placed there. Deciding the layer a Service belongs to is difficult. Both application and domain Services are usually built on top of domain Entities and Values providing required functionality directly related to those objects. While working on the model and during the design phase, we need to make sure that the domain level remains isolated from the other levels. Those services are even more difficult to separate from their counterparts residing in the domain layer. There can also be services in the application layer MODEL-DRIVEN DESIGN│39which adds a supplementary level of complexity. It is easy to get confused between services which belong to the domain layer, and those belonging to the infrastructure. While using Services, is important to keep the domain layer isolated. Define the interface in terms of the language of the model and make sure the operation name is part of the Ubiquitous Language. When a significant process or transformation in the domain is not a natural responsibility of an Entity or Value Object, add an operation to the model as a standalone interface declared as a Service.
![infoq domain driven design infoq domain driven design](https://res.infoq.com/presentations/ddd-microservices/en/slides/sl1.jpg)
The operation performed refers to other objects in the domain. The operation performed by the Service refers to a domain concept which does not naturally belong to an Entity or Value Object.Ģ.