Architecture Ramble: Relationship between several kinds of relationships in UML: inheritance, realization, dependence, association, aggregation, combination

Source: Internet
Author: User

This is a tutorial on the basics of UML; now that we're doing a project too tight, we haven't really done a real class-level detail design, let alone using UML to implement canonical modeling; This article is mainly about the relationship between several classes that I have been confused about before, Let's make it clearer when we really use UML for example class diagram design, and here are some of the relationships:

Inherited

Refers to the ability of a class (called a subclass, sub-interface) to inherit the functionality of another class (called the parent class, the parent interface) and to augment its own new functionality, which is the most common relationship between a class and a class or interface and interface, in Java where such relationships are explicitly identified by the keyword extends, In the design of the general is not controversial;

Realize

Refers to a class class implementation of the interface interface (can be multiple) function, the implementation is the most common relationship between the class and interface, in Java such relationships through the keyword implements clearly identified, at design time is generally not controversial;

Depend on

It can be simply understood that a class A uses another Class B, which is contingent, temporary, and very weak, but changes in class B affect A; For example, if someone wants to cross the river and borrow a boat, then the relationship between the man and the ship is dependent; At the code level, For Class B as a parameter is used by Class A in a methods method;

Association

He embodies a strong dependency between the two classes, or the semantic level of the class and interface, such as me and my friends; this relationship is more than relying on the contingency, the relationship is not temporary, generally long-term, and the relationship between the two sides is generally equal, the association can be one-way, two-way At the code level, the associated class B appears as a class attribute in the association Class A, or the association Class A refers to a global variable of the type being associated with Class B;

Polymerization

Aggregation is a special case of association relationship, he embodies the whole and part, the relationship of ownership, that is, the relationship between the whole and the part is has-a, they can have their own life cycle, some can belong to multiple whole objects, can also be shared for multiple whole objects, such as computer and CPU, The relationship between the company and its employees, and the expression at the code level, and the association is consistent, can only be differentiated from the semantic level;

Combination

The combination is also a special case of the relationship, he embodies a contains-a relationship, which is stronger than aggregation, also known as strong aggregation, he also embodies the relationship between the whole and part, but at this time the whole and part is not divided, the whole life cycle end also means that part of the life cycle end , such as you and your brain; At the level of the code, the relationship is consistent and can only be differentiated from the semantic level;

There is little doubt about the inheritance and realization of these two relationships, they embody a kind of class and class, or the vertical relationship between the class and the interface; the other four relationships embody the class and class, or the reference between the class and the interface, the transverse relation, is more difficult to distinguish between, there are many things between the relationship to prepare for positioning is very difficult, These kinds of relationships are semantic level, so from the code level does not completely distinguish between the various relationships, but in general, the following relationships show the degree of strength: Combination > Aggregation > association > dependency;

This article was reproduced from: http://blog.csdn.net/sfdev/article/details/3906243

This article can also: http://blog.csdn.net/suxinpingtao51/article/details/8011335

Architecture Ramble: Relationship between several kinds of relationships in UML: inheritance, realization, dependence, association, aggregation, combination

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.