Relationships between classes

Source: Internet
Author: User

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,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.