5 Kinds of Relationships Between Classes and Classes in UML
Source: Internet
Author: User
Keywordsuml class diagram uses relationship aggregation relationship in uml class relationships in uml
UML represents the five types of relationships between classes, including: inheritance relationship, realization relationship, dependency relationship, association relationship.
Simple Application Server USD1.00 New User Coupon
* Only 3,000 coupons available.
* Each new user can only get one coupon(except users from distributors).
* The coupon is valid for 30 days from the date of receipt.
1. Inheritance relationship Inheritance refers to the ability of a class (called subclass, subinterface) to inherit the functions of another class (called parent class, parent interface), and to add its own new functions. In Java, the inheritance relationship is clearly identified by the keyword extends, which is generally not controversial in design. In UML class diagram design, inheritance is represented by a solid line with a hollow triangle arrow, from the subclass to the parent class, or the subinterface to the parent interface.
2. Realization relationship Realization refers to the function that a class implements the interface interface (there can be multiple). Realization is the most common relationship between a class and an interface. In Java, this kind of relationship is clearly identified by the keyword implements, and is generally not controversial in design. In the UML class diagram design, the realization is represented by a dashed line with a hollow triangle arrow, pointing from the class to the realized interface.
3. Dependency relationship Simply understand, dependency is that one class A uses another class B, and this use relationship is accidental, temporary, and very weak, but the change of class B will affect class A. For example, if someone wants to cross a river and needs to borrow a boat, the relationship between people and boat is dependence. At the code level, class B is used as a parameter by class A in a method. In the UML class diagram design, the dependency relationship is represented by a dotted line with an arrow pointing from class A to class B.
4. Association relationship Association reflects a strong dependency on the semantic level between two classes, such as my friend and me. This relationship is stronger than dependency, there is no accidental dependency, and the relationship is not temporary. , Is generally long-term, and the relationship between the two parties is generally equal. The association can be one-way or two-way. At the code level, the associated class B appears in the associated class A in the form of class attributes, or the associated class A references a global variable of the associated class B. In the UML class diagram design, the association relationship is represented by a solid line with arrows pointing from the association class A to the associated class B, and the roles and multiplicity marks of the associated parties can be marked at both ends of the association.
5. Aggregation relationship Aggregation is a special case of association relationship. It reflects the relationship between the whole and the part, that is, the has-a relationship. At this time, the whole and the parts are separable, they can have their own life cycles, and the parts can belong to multiple integral objects, or they can be shared by multiple integral objects. For example, the relationship between computers and CPUs, companies and employees, for example, an aircraft carrier formation includes sea and air carriers, destroyers, carrier-based aircraft, and nuclear-powered attack submarines. At the code level, it is consistent with the association relationship and can only be distinguished from the semantic level. In the UML class diagram design, the aggregation relationship is represented by a hollow diamond and a solid arrow.
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.