Where is the boundary of the domain model and application services in?

Where is the boundary of the domain model and application services in?

Boundary treatment is often a more difficult problem. Just like the military demarcation line, as sometimes you will feel you belong to each other's sites, the other party and feel of your site belongs to him, and then asked to re-re-divided. Border is often the case, often conflict.

Border application services and domain models did not like the idea of ​​two mischief so complicated, because they have rules and logic. So long as you understand what is service and what is the domain model can solve this seemingly chaotic border.

Application services and generate domain model

Emergence application services and domain model of software development is a product of the historical process. In the field of logic is the beginning of chaos, and there is no domain model, but simply a transaction script. During this period, a script corresponding to a business use case. This is no problem for simple business terms, and very convenient. But the model object when the transaction script in operation more than two, then the transaction becomes complicated script, he completed these model objects all the business logic. In this period he served as a transaction script all the business logic. With the increasing complexity of the business, abstract problem solving domain of people have become more realistic. At this time, non-procedural, object-oriented programming is also becoming more popular, so it is time the business affairs of the script logic to the domain model to solve. Since the transaction script is divided into two, fine-grained domain model reflects the business logic, but the domain model used in the process of fine-grained and relatively cumbersome and complicated, we often coarse-grained business processes use case model to express, so we requires a set of fine-grained model class art encapsulated into coarse-grained model for client calls use case, this group of packages use case model class known as application service class.

Application service contain?

The above analysis is generated application service from a business perspective, this is the main cause, then also from a technical point of view to explain the content of the application service.

1, database transactions, we contacted a lot in this regard, not too much introduction.

2, service method parameter, if the small number of parameters, you can write directly on the method parameter. But many parameters, you might use a DTO to encapsulate parameters. In my opinion DTO used as a parameter is not a good model.

Why do I think DTO encapsulation method parameter is not a good model?

Why DTO as a parameter, because many parameters. What seems reasonable grounds.

I will apply the service methods into performing an action type and operating property type.

Operational attribute type method is mainly operating on the real property, which is the data model looks like, yes, at this moment, in this context is the major update properties. (There is a misconception in the object-oriented class contains properties and methods, but they are not necessary. There is no way not to say that the class is not a domain model, domain model is based on business analysis and design, he is a reflection of the business, rather than to technical skills). When you package into the attribute type method parameter DTO just do copy on the real property, it makes no practical sense, and if so why not just use it as a parameter entity classes. This multi-move, although the same can be achieved needs, but this is not a reason to use it.

3, security permissions, everything needs a wall of defensive walls, in order to ensure internal stability. The same application service needs with regard to safety in two ways: Role-based access control (RBAC), which is a coarse-grained access control, to determine whether he has access rights based on user role has. The other is the access control list (ACL), which is a fine-grained access control, to determine whether he has access rights based on user authority to operate a single record. Such as user rights to files, LDAP access control entry in the ACL are used. In application development, Spring Security supports RBAC and ACL in two ways.

4, application service method returns a value, the method returns the parameter value and the like, but for both DTO package, there is an argument for the view field layer by layer and the application layer is isolated, so that the domain model is not compromised. The idea is unrealistic, inconsistent with the real domain model DTO and if the return value to be returned, it is the lack of integrity, if consistent why need to use a DTO package again, return directly to the domain model return is not on the list.

Asked Questions

Many people say that I am using the command object (XxxCommand) as a parameter?

Ah ha, is not named XxxCommand command object for this parameter passing XxxCommand DTO and what are the major differences?

That it should be implemented DTO Where?

View layer. Now view shows have a lot of ways, such as: RESTful, GraphQL, HTML, and so on. This layer is the model to deal with specific areas of port DTO place.

to sum up

I will break down the script from the transaction history of the development and business perspective into the origin of software application services and domain models. And from a technical point of application service parameter, affairs, rights, the return value aspects do some explaining. Not so much the border issue and field service applications model as it calls their relationship.

More comprehensive content can refer to the "Enterprise Application Architecture" p.93.

For questions, please add QQ group discussion:

image

Released three original articles · won praise 0 · Views 7

Guess you like

Origin blog.csdn.net/tgioer/article/details/104211176