UML Class Diagram

Source: Internet
Author: User
Tags dashed line

Generalization relationship (generalization)

The inheritance structure of a class is represented in UML as: generalization (generalize) and implementation (realize):

The relationship of the inheritance relationship is is-a, and if the two objects can be represented by is-a, it is an inheritance relationship: (.. Be ...)

Eg: Bicycles are cars, cats are animals

A direct representation of a generalized relationship with a hollow arrow, as indicated (a inherits from B);

Eg: automobiles are realized in reality and can be used to define specific objects; The generalization relationship between the automobile and the SUV;

Note: In the final code, the generalization relation is represented as inheriting non-abstract class;

Implementation relationship (realize)

The implementation relationship is represented by a dashed line with a hollow arrow;

Eg: "Car" is an abstract concept, in reality it is not directly used to define the object, only the specific sub-class (car or bicycle) can be used to define the object ("Car" class in C + + with abstract class representation, in Java has the concept of interface, more easily understood)

Note: In the final code, the implementation relation manifests as inheriting abstract class;

Aggregation Relationship (aggregation)

The aggregation relationship is represented by a straight line with a hollow diamond arrow, such as an aggregation of A to B, or b consisting of A;

The aggregation relationship is used to represent the relationship between entity objects, which represents the whole part of the semantics; For example, a department consists of multiple employees;

Unlike the combinatorial relationship, the whole and the part are not strongly dependent, even if the whole does not exist, the part still exists; For example, the department is withdrawn, the people do not disappear, they still exist;

Composition relationship (composition)

A composite relationship is represented by a line with a solid diamond arrow, such as a composition B, or b consisting of A;

As with the aggregation relationship, the composition relation also represents the whole part of the semantics, for example, the company is composed of several departments;

But the combinatorial relation is a kind of strong dependence special aggregation relation, if the whole does not exist, then the part also does not exist; For example, the company does not exist, and the department will not exist;

Association Relationship (Association)

An association relationship is expressed in a straight line; it describes the structural relationship between objects of different classes; it is a static relationship, usually independent of the running state, generally determined by common sense and other factors; it is generally used to define static and natural structures between objects; Therefore, the association relation is a kind of "strong association" relationship;

For example, between the passenger and the ticket is an association relationship; students and schools are an association;

The association relationship by default does not emphasize direction, which means that objects know each other, and if the direction is particularly stressed, for example, indicates that a knows B, but B does not know A;

Note: In the final code, the associated object is usually implemented in the form of a member variable;

Dependency relationship (dependency)

A dependency is represented by a set of dashed lines with arrows, such as a dependent on B; He describes the relationship of an object to another object while it is running;

Unlike association relationships, it is a temporary relationship that usually occurs during operation and changes with the runtime, and dependencies can change;

Obviously, the dependence also has the direction, the bidirectional dependence is one kind of very bad structure, we should always maintain one-way dependence, eliminates the bidirectional dependence the generation;

Note: In the final code, the dependency relationship is represented as an incoming parameter of the class construction method and the class method, the arrow points to the call relationship, the dependency processing temporarily knows the other side, or "uses" the other's methods and properties;

UML Class Diagram

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.