UML relationships (generalization, implementation, dependency, Association (combination, aggregation ))

Source: Internet
Author: User

The construction of UML quickly includes three types:

(1) Things (4 types): Structured things, behavioral things, grouping things, and commenting things

(2) relationship (4 types): generalization, implementation, dependency, and Association

(3) diagram (10 types): use case diagram, class diagram, object diagram, package diagram, component diagram, deployment diagram, state diagram, activity diagram, sequence diagram, and collaboration Diagram

Things are the abstraction of the most representative components in the model; links combine things; graphs aggregate related things.

 

 

(2) relationship (4 types)

In UML, the relationships between classes and classes, classes and interfaces include: generalization, association, and dependency) link, implementation (realization) link.

 

A generalized relationship is a function that inherits from another class (called the parent class and parent interface, it can also add its own new function capabilities. inheritance is the most common relationship between classes or interfaces and interfaces. in Java, such relationships are identified by the keyword extends, it is generally not controversial during design.

The implementation (realization) relationship refers to the function of a class to implement interface interfaces (multiple); implementation is the most common relationship between classes and interfaces; in Java, such relationships are identified by the keyword implements, which is generally not controversial during design;

Dependency relationship: it is also a connection between classes. It indicates that one class depends on the definition of another class. Dependency is always one-way. It can be simply understood that a class A uses another class B, and this relationship is contingent, temporary, and very weak, but changes in Class B will affect a. For example, if someone wants to cross the river and borrow a ship, the relationship between people and the ship is dependent. It is manifested in the Code layer, class B is used by Class A in a method as a parameter.
In Java, dependency is embodied in local variables, parameters in methods, and calls to static methods.



 

Association: indicates the connection between a class and a class. It allows a class to know the attributes and methods of another class.
You can use a single arrow to indicate one-way Association. You can use a double arrow or an arrow to indicate two-way Association. We do not recommend two-way Association. there are two endpoints associated. Each endpoint can have a base number, indicating that the associated class can have several instances.
Common bases and meanings:
0 .. 1:0 or 1 instance.
0 .. *: there is no limit on the number of instances.
1: only one instance is allowed.
1 .. *: there must be at least one instance.

It represents a strong dependency between two classes or between classes and interfaces, such as my friends and I; this relationship is more dependent than the dependency relationship, with no dependency relationship. The relationship is not temporary, and is generally long-term. In addition, the relationship between the two parties is generally equal and manifested in the Code layer, for associated Class B, it appears in the form of class attributes in associated Class A, or it may be that associated Class A references a global variable of the type of associated Class B; in Java, associations are implemented using instance variables.



 
Aggregation: a special case of association, which is a strong association. aggregation is the relationship between the whole and the individual, that is, the relationship between has-a. At this time, the whole and the part can be separated and they can have their own lifecycles, some can belong to multiple overall objects, or share multiple overall objects, such as the relationship between the computer and CPU, the company and the employee, and so on. The performance is at the code level and the relationship is consistent, it can only be distinguished from the semantic level;

The aggregation relationship is also implemented using instance variables. Java syntax does not allow cross-linking and aggregation.

In an association, two classes are at the same level, while in an aggregation relationship, two classes are at an unequal level. One Class indicates the whole, and the other class indicates the part.



 
Composition: it is also a special case of association. It represents a contains-a relationship that is stronger than aggregation, also known as strong aggregation; it also shows the relationship between the whole and the part, but the whole and the part are inseparable at this time, and the end of the overall life cycle means that part of the life cycle ends; for example, you and your brain; the compositing relationship cannot be shared .. It is represented at the code level and is consistent with the association. It can only be distinguished at the semantic level.

The combination is almost the same as aggregation. The only difference is that "part" cannot exist independently from "whole", that is, the life cycle of "part" cannot be longer than "whole.

Summary:

There is no doubt about the relationship between inheritance and implementation. They reflect the vertical relationship between a category and a class, or between a class and an interface; the other four relationships reflect the reference and horizontal relationships between classes and classes, or between classes and interfaces, which is difficult to distinguish, there are many relationships between things. It is very difficult to prepare for positioning. As mentioned above, these relations are all semantic-level, so they cannot be fully differentiated from each other at the code level; in general, the strength of the last several relationships is: Combination> aggregation> association> dependency.

Reprinted from http://justsee.iteye.com/blog/808799

Thanks http://www.uml.org.cn/oobject/201006114.asp

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.