Read UML class Diagrams and time series diagrams

Source: Internet
Author: User
Tags dashed line

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

This chapter all graphics use Enterprise Architect 9.2来 painting, all demo sample See design_patterns under the root folder. Eap

Start with a demo sample

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 with the SUV. The relationship between them is a generalization relationship, using a solid line with a hollow arrow to represent;
  • Between the car and the engine is a composite relationship, using a solid line with a filled arrow representation.
  • 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;
  • Students need to use bicycles to go to school, and bicycles are a kind of dependency. Use a dashed line with arrows;

These six relationships are described in detail below.

Relationship generalization relationship between classes (generalization)

The Inheritance structure table for classes is now in UML: generalization (generalize) and implementation (realize):

The inheritance relationship is a is-a relationship. The assumptions between the two objects can be expressed in is-a, which is the inheritance relationship: (.. Be ...)

Eg: Bicycles are cars, cats are animals

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

Eg: cars are realized in reality. A detailed object can be defined by a car, and a generalization relationship between the car and the SUV;

Note: Finally, in the code, the generalization relationship 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 possible to define objects directly, only to specify detailed subclasses (automobiles or bicycles) to define objects ("Cars", which are represented in C + + with abstract classes, have interfaces in Java, and are easier to understand)

Note: Finally in the code, the implementation of the relationship manifests as inheriting abstract classes;

Aggregation Relationship (aggregation)

The aggregation relationship is represented by a straight line with a hollow diamond arrow, for example to indicate a aggregation to B, or B to consist of A;

An aggregation relationship is used to represent the relationship between entity objects, representing the semantics of the whole part, such as a department composed of multiple employees;

Different from the composition relationship. The general and the part are not strongly dependent, even if the population does not exist. Part still exists; The department has withdrawn, the people will not disappear, they still exist.

Composition relationship (composition)

A composite relationship is represented by a straight line with a solid diamond arrow, for example to indicate that a consists of B, or b consists of a.

Same as the aggregation relationship. The same composition relationship represents the semantics of the overall component. For example, the company is composed of several departments;

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

Association Relationship (Association)

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

For example, a relationship between a passenger and a ticket is an association. Students and schools are an association relationship;

An association relationship defaults to a direction, which means that objects know each other. Assume special emphasis on direction, for example with. The expression a knows B, but B does not know A;

Note: In the last code, the associated object is generally implemented as a member variable.

Dependency relationship (dependency)

Dependencies are represented by a set of dashed lines with arrows. For example to indicate that a depends on B. He describes the relationship between an object and an object that is used during execution.

Unlike association relationships, it is a temporary relationship that is usually generated during execution. And as the implementation changes, the dependencies may change;

Obviously, the dependence also has the direction. Two-way dependency is a very bad structure. We should always keep one-way dependence and prevent the generation of two-way dependence;

Note: In the last code. Dependencies are embodied in the class construction method and the incoming parameters of the class method. The arrows point to the calling relationship; dependency processing temporarily knows the other side, or "uses" the other's methods and properties.

Timing Diagram

In order to show the interactive details of the objects, the sequence diagram is used to introduce each pattern in the design pattern.

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 with the interacting objects and their objects.

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

About time series diagrams. The following article will cover more specific concepts, many other embodiments of the application, and perhaps chapters involved in the sequence diagram pattern;

Read 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.