What is the anemia model and what is the congestion model? Why do we force the use of anemia models?

This is the back-end small class of the monastery. Each article is shared from

[background introduction] [knowledge analysis] [common problems] [solutions] [coding practice] [extended thinking] [more discussion] [References]

Eight aspects of in-depth analysis of back-end knowledge / skills. This article shares:

[what is the anemia model, what is the congestion model? Why do we force the use of anemia model?]

Hello, I'm wang Dongdong, the 13th student of Shenzhen Branch of it Academy. I'm an honest, pure and kind java programmer.

Today, I'd like to share with you the first task of Java on the official website of the Academy, expanding the knowledge points in thinking - what is the anemia model and what is the congestion model? Why do we force the use of anemia models?.

1、 Background introduction

Domain model is a visual representation of concept classes in the domain or objects in the real world. It is also called conceptual model, domain object model and analysis object model. It can be divided into four categories: blood loss model, anemia model, congestion model and blood swelling model.

2、 Knowledge analysis

1. What is anemia model?

Anemia model means that only setter and getter methods (POJO) are used in the domain object, and all business logic is not included in the domain object, but placed in the business logic layer.

2. What is congestion model?

Congestion model puts most business logic and persistence in domain objects, and business logic only completes the encapsulation of business logic, transaction and permission processing. It is more object-oriented.

3、 Frequently asked questions

Why should we force the use of anemia model?

4、 Solution

The hierarchical structure of the system is clear, and each layer depends on each other in one direction.

Low coupling, convenient for later update and maintenance.

The design is simple and the underlying model is stable.

5、 Coding practice

6、 Extended thinking

Comparison between anemia model and congestion model:

The biggest difference between them is how to divide the business logic.

The anemia model entity class only has the set get method, the logic is basically implemented in the service layer, and the code is concentrated in the service layer. The coupling is very small, which is convenient for team cooperation.

In the entity class of congestion model, there are not only states, but also behaviors, that is, attributes and methods. Its service layer is very thin, and the business logic only completes the encapsulation of business logic, transaction and permission processing. High requirements for personal technical level.

Note: if you are a beginner of Java, please point it out. Thank you!

7、 References

Baidu Encyclopedia, blog Park, CSDN

VIII More discussion

1. There is no implementation method in the anemia model. Where is its addition, deletion, modification and query implemented?

The anemia model requires a DB layer at the glass for database operations.

2. What are the disadvantages of anemia model?

The logic is concentrated in the service layer, resulting in too heavy service.

3. Anemia model or congestion model in typical web applications? Why?

Use anemia model

In typical web applications, simple CRUD operations account for the vast majority of business logic, which can avoid the problem that business logic has to encapsulate a large number of Dao interfaces, simplify the software architecture design and save a lot of business layer code.

(1) It is based on component technology. All application objects, whether controllers, views, or business objects, are Java components, and are closely integrated with other infrastructure provided by spring

(2)

It does not depend on the servlet API (although the target is so, it does depend on the servlet when implemented)

(3) You can use any view technology, not just JSP

(4) Support the mapping strategy of various request resources

(5) It should be easy to expand

That's all for today's sharing. You are welcome to like, forward, leave messages and make bricks~

Ppt link video link

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>