I understand the OOP--UML six relationships

Source: Internet
Author: User
Tags dashed line

    • Recently, because often to the company's small partners to talk about the basic things of OOP, every time the papyrus is embarrassed by me, painting to paint their own mess, and sometimes try to use UML to express the relationship between classes, but the UML has never been contacted after graduation, often by the small partners point out that inheritance should be a solid line, The combo diamond is solid ... , good embarrassment, finally learn from the mistakes of the system.

UML defines the relationship mainly: generalization, implementation, dependency, association, aggregation, combination, these six kinds of relations closely in order to strengthen, look at

Generalization

concept: generalization is a kind of general and special , General and specific relationship between the description, the specific description is based on the general description, and extended it. Implemented in a program by inheriting classes. For example, a dog is a specific description of animals, in object-oriented design when the dog is generally designed as a subclass of animals.

representation method: solid line of a hollow triangular arrow, sub-class pointing to the parent class

Realize

Concept: implementation is a class-to-interface relationship, which indicates that the class is an implementation of all the characteristics and behavior of the interface, which is generally described by the class implementation interface in the program.

Presentation method: dashed line with hollow triangular arrows to implement class pointing interface

Depend on

concept: is a use of the relationship, that is, the implementation of a class requires the assistance of another class, so as far as possible to avoid the use of bidirectional interdependence, in the program is generally shown in Class A method requires Class B instance as its parameters or variables, In itself, Class A does not need to reference the instance of Class B as its member variable.

Presentation method: Dashed arrow, Class A points to Class B.

Association

Concept: represents a join between a class and a class, which enables a class to know the properties and methods of another class, a relationship that is more powerful than a dependency, a relationship that is not temporary, and generally long-term, in which the associated Class B appears in the association Class A in the form of a class attribute. It is also possible that the Association Class A refers to a global variable of type class B that is associated with

Presentation method: solid arrow, Class A points to Class B

Polymerization

Concept: A special case of the aggregation association, which is a strong correlation relationship. Aggregation is the relationship between the whole and the individual, that is, the relationship between the has-a, the whole and the individual can have their own life cycle, some can belong to more than one whole object, can also be shared for multiple whole objects. The aggregation and association relationships in the program are consistent and can only be differentiated from the semantic level;

Presentation method: A solid arrow with a hollow diamond at the tail (or no arrows), Class A points to Class B

Combination

concept: A combination is also a special case of an association relationship. A combination is a relationship between the whole and the part, that is, the relationship of Contains-a, which is stronger than aggregation. Part is consistent with the whole life cycle, and the end of the whole life cycle means that part of the life cycle ends, and the combined relationship cannot be shared. The composition and association relationships in the program are consistent and can only be differentiated from the semantic level.

Presentation method: An implementation arrow with a solid diamond at the tail (or no arrows), Class A points to Class B


I understand the OOP--UML six relationships

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.