Author: Anders James
Why domain model?
Traditional development methods: database-based design and development. The design model provided by the database is table and field granularity. These two granularities are sometimes not suitable for System Design:
1. Structural capabilities of the Model
1.1. design advantages of components in the same module. A model can be aggregated from data in multiple tables, and a table can aggregate multiple models. A logic is to aggregate several fixed or non-fixed fields; the associations between models cannot be displayed using tables (foreign key constraints are too limited for system development ). These are not supported regardless of the table or field granularity!
1.2. The model method is used to easily solve the project integration problem (when two components of different modules access the same table)
2. Structural capabilities of the Architecture
The transaction script directly accesses the table. In other words, the architecture is only service + database table. In this architecture, database table is our model.
Here we will look at the impact of domain model on the architecture in the logic design.
A. Service, model, and repository. The reconstruction and Association of model are completed by repository, and a single data logic is handed over to model (generalization is supported)
B. Benefits of testing
3. Unified Analysis and Design
Communication issues, Customers focus on their businesses, the analysis model is close to the customer's needs, the design also uses the model approach, to avoid the separation of analysis and design. It facilitates communication between it and Ba (customers)
4. Other benefits
. The domain model can shield persistent information. The table design of the persistence design is related to the DBA. the DBA has the right to design the table, and the model can effectively isolate their work;
4.2.model can solve performance problems transparently through many means. Using a table as a model can easily lead to performance problems. Of course, it is not impossible to solve the problem. One is using dataset, however, such switching costs are high.
Architecture of application domain
As mentioned above, in the logic design, the implementation of domain model divides the architecture into service, model and repository. The persistence, reconstruction, and Association of model are completed by repository; the single data logic (dependent on its own data information and associated data) is attributed to model (supports generalization); the Service focuses on task processing, which is equivalent to a macro flow, including multiple model processing, and other service calls.
The following are:
Domain service | Repository
Domain object |
Repository and Dao
Repository is a special service that does not process tasks. Instead, it provides model persistence, reconstruction, and query. Because most enterprise applications implement persistence through databases, the integration design between repository and traditional Dao is very important.
There are three known design methods:
1. Two interfaces and two implementation classes. The repository and Dao interfaces are independent, and the request is forwarded to the DAO implementation class through the repository implementation class.
This method is orthodox, but the maintenance cost is too high; A single update can be changed everywhere at most.
2. Two interfaces are one implementation class. The repository and Dao interfaces are independent. An implementation class implements two interfaces at the same time.
This method greatly simplifies maintenance costs. Only one interface and one implementation class can be modified at most for one update.
3. Two interfaces are one implementation class. Different from the above, the DaO interface inherits the repository interface, and an implementation class implements the DaO interface.
The maintenance cost of this method is similar to the previous one, but when the interface method flows between the two interfaces, it can be done through development tools.
In addition, the DAO implementation class is also a part of the high development and maintenance costs in the work. You can reduce the development cost through code generation. For more information, see ibatis.