Ps:
Composite relationship: solid, a Class A belongs to another class, or multiple classes, but Class A cannot exist alone to use, a is generally an abstract thing
Aggregation relationship: Hollow, a Class A can be used alone
The method of a is called directly, regardless of the combined aggregation.
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;
Below we will introduce these six relationships;
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 objects, the sequence diagram is used for subsequent chapters of the design pattern parsing.
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 the time series diagram, the following article will be a detailed description of the concept, more examples of applications, to participate in the subsequent chapters in the pattern of the sequence diagram;
http://smartlife.blog.51cto.com/1146871/284874
Appendix
Define an abstract class in the EA (its version is "abstract")
Transferred from: http://blog.csdn.net/tianhai110/article/details/6339565
[Turn] to understand UML class diagrams and time series diagrams