In the domain model, there are four relationships between classes
1. Association (Association)
A reference relationship between classes can have a pair of one or one-to-many and many-to-many, such as a one-to-many between customer and order
publicclass Order{ // 与order对象关联的Customer对象 private Customer customer;}
The above Code establishes an association from the order class to the customer class, as well as the Association of the Order class from the customer class, since a customer object will correspond to multiple order objects, so An Orders collection should be defined in the customer class to hold all orders generated by the customer.
publicclass Customer{ // 与所有Customer对象关联的Order对象 privatenew HashSet();}
2. Dependence (Dependency)
Dependency is a kind of access relationship between classes, if Class A accesses a property or method of Class B, or class A is responsible for instantiating Class B, then Class A relies on Class B. Unlike association relationships, Ray B is not defined as a property of Class A.
There are three types of dependencies:
1. Class A is a local variable in class B (a method).
2. Class A is a parameter of class B method;
3. Class A sends messages to Class B, which affects the change of Class B;
Driver relies on car
3. Polymerization (Aggregation)
Aggregation refers to the relationship between the whole and the part, which is relatively uncommon between entity objects. For example, people and hands are an aggregation relationship
publicclass Persion{ privatenew HashSet<Hands>();}
4. Generalization (generalized generalization)
Generalization is embodied in the class as an inheritance relationship, which is easier to understand, such as the panda inherits the animal
publicclass Pandan extends Animial{}
Mastering the relationship between hibernate--domain objects