UML (Unified Modeling Language) class diagram __uml

Source: Internet
Author: User
Tags dashed line

UML Class diagram: To understand the class diagram of the lines between the various classes, what the arrow means is enough to deal with day-to-day work and communication, and we should be able to match the meaning of the class diagram to the final code; With this knowledge, there is no problem with the design pattern structure diagram;

All graphics in this chapter use Enterprise Architect 9.2来 painting

Start with an example: see the following class diagram, the relationship between classes is what we need to focus on
The class diagram structure of the vehicle is <<abstract>> the car is an abstract class; it has two inheriting classes: cars and bicycles; the relationship between them is to implement the relationship, using a dashed line with a hollow arrow; the car is also an inheritance relationship with the SUV, The relationship between them is a generalization relationship, using solid lines with hollow arrows; the combination of the car and the engine is expressed by the solid line with the black Arrow; the student and the class is the aggregation relation, uses the solid line which has the hollow arrow to express; The student and the identity card are the correlation relations, uses one solid line to express; Students need to go to school to use bicycles, and bicycles is a dependency, using a dotted line with arrows to express;

Below we will introduce these six kinds of relations;
Class relationship to Class-inheritance:
An inheritance relationship is a is-a relationship; two objects, if they can be represented by is-a, are inherited: (... Yes ...)

Eg: Bicycles are cars, cats are animals

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

The generalization relation is represented by a straight line with a hollow arrow, as shown in the following figure (a inherits from B);

Eg: the automobile is realized in reality, the specific object can be defined by the car, and the generalization relation between the car and the SUV;

Note: In the final code, the generalization relation behaves as inheriting the 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 objects; it can be used to define objects (car or bike), which is defined as an abstract class in C + +, with the concept of interface in Java, easier to understand.


Note: In the final code, the implementation relationship behaves as an inherited abstract class;

Aggregation Relationship (aggregation)
The aggregation relationship is represented by a straight line with a hollow diamond arrow, and the following figure represents a aggregation to B, or b is composed of A;

An aggregation relationship is used to represent a relationship between entity objects, representing a part-by-component semantics, such as a department consisting of multiple employees;

Unlike combinatorial relationships, the whole and partly are not strong-dependent, and even if the whole does not exist, parts still exist; For example, the department is withdrawn, the personnel do not disappear, and they remain;

Combinatorial relationships (composition)
A combination relationship is expressed in a straight line with a solid diamond arrow, and the following figure indicates a composition B, or b consists of A;


Like an aggregation relationship, a combinatorial relationship also represents a part-by-component semantics, such as a company made up 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, the department will not exist;

Association Relationship (Association)
The association relation is expressed in a straight line; it describes the structural relationships 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 relation is a kind of "strong association" relationship;

For example, the bus and ticket is a relationship between the students and the school is a correlation;

The association relationship defaults to a direction, indicating that the objects are known to each other, and if special emphasis is placed on the direction, the following figure 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;

Dependencies (dependency)
A dependency is represented by a set of dotted lines with arrows, and the following figure indicates that a relies on B; He describes the relationship between an object and another object during the run;


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

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

Note: In the final code, the dependency is embodied in the class construction method and the incoming argument of the class method, and the arrow is directed to the calling relationship, and the dependencies are "using" each other's methods and attributes in addition to the temporary knowledge of the other;

Sequence diagram
In order to show the interaction between the object details, subsequent to the design pattern parsing chapters, will be used in the sequence diagram;

A sequence diagram (Sequence Diagram) is a graph that shows the interactions between objects, which are arranged in chronological order. The sequence diagram shows the order in which the messages interact between the objects participating in the interaction and their objects.

The modeling elements included in the sequence diagram are: Objects (Actor), lifelines (Lifeline), control focuses (focus), messages (message), and so on.

Original source:
Http://design-patterns.readthedocs.io/zh_CN/latest/read_uml.html

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.