The little knowledge

Some nouns to know

1. Domain Driven Design (DDD)

2. MVC three-tier architecture: M represents Model, V represents View, and C represents Controller. It divides the whole project into three layers: presentation layer, logic layer and data layer. Many projects are now separated from the front and back ends, with the back end responsible for exposing interfaces to the front end. Divide the back-end projects into the Repository layer, Service layer, and Controller layer. The Repository layer is responsible for data access, the Service layer for business logic, and the Controller layer for exposing interfaces.

Anemia model

Classes that contain only data, but no business logic, are called Anemic Domain models. As follows: UserBo is a pure data structure, containing only data and no business logic. The business logic is centralized in UserService. We operate UserBo with UserService. In other words, the data and business logic of the Service layer are split into BO and Service classes.

// Service+BO(Business Object) //
public class UserService { 
	private UserRepository userRepository; // Inject via constructor or IOC framework
	public UserBo getUserById(Long userId) { UserEntity userEntity = userRepository.getUserById(userId); UserBo userBo = [...convert userEntity to userBo...] ;returnuserBo; }}public class UserBo {// omit other properties, get/set/construct methods
	private Long id; 
	private String name; 
	private String cellphone;
}
Copy the code

This anemic model, which separates data from operations and destroys object-oriented encapsulation, is a typical procedural programming style.

Congestion model

A class in which data and corresponding business logic are encapsulated into the same class is called a congestion model.