UML classifies the relationships between classes into five types:
I. Association
Association refers to the specific correspondence between classes. Its essence is the relationship between class objects.
The associations of the two classes are divided into one-to-one, one-to-many, and multiple-to-many.
Indicates the association between the customer class and the order class. The association relationship indicates that the object of the customer class corresponds to the object of the Order class. In this example, there is a one-to-many relationship, that is, an object of the customer class corresponds to multiple objects of the Order class. If Class A is associated with Class B, Class A contains class B attributes.
Define order class
1 Class Order { 2 Private Customer customer; 3 Public Void Setcustomer (customer ){ 4 This . Customer = Customer; 5 } 6 Public Customer getcustomer (){ 7 Return This . Customer; 8 } 9 } View code
The code above defines the association between the order class and the customer class. Next, define the association between the customer class and the order class.
1 Public Class Customer ( 2 Private Set <order> orders = New Hashset <order> (); 3 Public Void Setorders (set orders ){ 4 This . Orders = Orders; 5 } 6 Public Set getorders (){ 7 Return This . Orders; 8 } 9 )
II,
III,
IV,
V,