Understand UML class diagrams and time series diagrams

Source: Internet
Author: User
Tags dashed line

Understand UML class diagrams and time series diagrams

The various elements of UML are not mentioned here, I just want to talk about the relationship between classes in the class diagram, can understand the class diagram of the lines between the classes, arrows represent what meaning, it is enough to deal with daily work and communication, at the same time, we should be able to express the meaning of the class diagram and the final code corresponding; Look at the design pattern structure of the later chapters there is no problem;

All graphics in this chapter use Enterprise Architect 9.2来, and all examples are described in the root directory of Design_patterns. Eap

Starting from an example

Consider the following class diagram, where the relationship between classes is what we need to focus on:

    • The class diagram structure of the car is <<abstract>>, which means that the car is an abstract class;
    • It has two inheritance 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 between the SUV, the relationship between them is a generalization relationship, using a solid line with a hollow arrow representation;
    • Between the car and the engine is a combination of relations, using a solid line with the arrows to express;
    • Between the student and the class is the aggregation relation, uses the solid line with the hollow arrow to represent;
    • The relationship between the student and the ID card is related, and a solid line is used to express it;
    • The student needs to go to school to use the bicycle, is a kind of dependence with the bicycle, uses the dotted line with the arrow to indicate;

These six relationships are described in detail below;

Relationship generalization relationship between classes (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;

Timing Diagram

In order to show the interactive details between the objects, the subsequent chapters introduce each pattern in the design pattern and use the time series diagram.

Time series diagrams (Sequence Diagram) are graphs that display the interaction between objects, which are arranged chronologically. The sequence diagram shows the order in which messages interact between the objects participating in the interaction and their objects.

The sequence diagram includes modeling elements such as: Object (Actor), Lifeline (Lifeline), control focus (focus on control), messages (message), and so on.

For time series diagrams, the following article will introduce a more detailed concept, more examples, and take part in the sequence diagram of the patterns in subsequent chapters;

http://smartlife.blog.51cto.com/1146871/284874

Appendix: "Pictorial design Mode"

This text is open source Book "Diagram design pattern" The first article, at present this book basically completes;

The book uses a combination of graphics and code to parse the design pattern;
Each pattern has a corresponding object structure diagram, and in order to show the interaction details between objects, I will use the time series to describe how it works, (in the state mode, it will also use the state diagram, the use of this diagram for understanding the state of the transformation is very intuitive)

For details, see: Https://github.com/me115/design_patterns

(GitHub contains all the source code in the book and the class diagram of each pattern)

Posted by: Big CC | 13nov,2014
Blog: blog.me115.com [Subscribe]

Understand UML class diagrams and time series diagrams

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.