Use gif to show the meaning of arrows and lines in UML, and understand UML class diagrams, sequence diagrams and use case diagrams

Preface

Entering a company, dealing with daily software development work and communication, to be able to understand the relationship between the various classes of code written by others, then you need to be able to understand the lines and arrows between the classes in the class diagram uml meaning?

In the UML class diagram, there are six relationships as follows:

Generalization (Generalization), Implementation (Realization), Dependence, Association (Association), Aggregation, Composition (Composition)

In order to avoid reading and remembering repeatedly, but still can't remember, use gif animation and humorous metaphor explanations to deepen their understanding.

Speaking from uml animated gif

 

The strengths of the six relationships of UML class diagrams are:
Generalization> Implementation> Combination> Aggregation> Association> Dependence

How to memorize these symbols more effectively?

Basic knowledge of class diagram notation

First of all, let's take a look at the symbols that express the relationship of class diagrams as a whole. The symbols of class diagram relationships are composed of three parts:

Arrows, lines and tails.


There are two arrow shapes, arrow and triangle arrow.

There are two types of line shapes, solid lines and dashed lines.

There are three types of arrow tail shapes: point, hollow diamond and solid diamond.


In summary, we can know that there are 2 x 2 x 3 = 12 kinds of symbols expressing the relationship of the class diagram, but there are only 6 kinds of relationships in the UML class diagram, so there are still 6 kinds of relationships that are not used.
After understanding the symbolic expression of class diagram relationships, let's look at the priority relationship of symbols.

Symbol priority

From the perspective of the composition of relationship symbols, we define the following priority relationships:

Arrow> Arrow Tail> Line
For Arrow: Triangular Arrow> Arrow
For Arrow Tail: Solid Rhombus> Hollow Rhombus> Point
For Line: Solid Line> Dotted Line 

Therefore, it is not difficult to draw from the above priorities: 

The six symbols above are the six relational symbol expressions defined in UML class diagrams.

Object relationships in application design patterns

Comparison of association and dependency

Dependency: dashed arrow

public class Person
{
    void buy(Car car)
   {
       ...
    }
}


The dependency relationship is embodied as the incoming parameters of the class construction method and the class method , and the arrow points to the call relationship ; the dependency relationship “uses” the other party’s methods and attributes in addition to temporarily knowing the other party .

Dependency is that there are attributes of type b in the member methods of type a, such as the attributes of water and air in the animal metabolism method . Only when this method is adjusted can it be temporarily used.

Association relationship: solid line

public class 徒弟
{  

}

public class 唐僧
{
     protected: list<徒弟> tdlist;
}

The connection between the class and the class (it makes one class know the attributes and methods of another class, and the association relationship is generally realized by member variables )
association is to indicate the dependency relationship between the class and the class or the class and the interface . It is "ownership"; specific to the code, it can be represented by instance variables .

Class A has a member variable that holds a reference to Class B , which means that Class B can be found by Class A, or there are objects of Class B in Class A, and there are climate attributes in Penguins . Tang Seng corresponds to multiple apprentices. , The teacher teaches the students, husband and wife , water bottle, etc ...

Comparison of combination and aggregation

Combination is present compositions separate class does not make sense ; polymerization are polymerized class in can be present alone significance.
In terms of life: the combination must be responsible for the life of the combined class; the aggregation is not responsible for the declaration period of the aggregated class , and it can be created and destroyed by an external program (assignment is available).

Combination relationship: solid diamond

class 肢
 {
 }
 class 人
 {
        protected:  肢   limb[4];
 }


Combinations have the same life cycle, people have limbs, people die, limbs no longer exist

Aggregation relationship: hollow diamond

public class 引擎
 {

 }
public class 轮胎
 {

 }
public class 汽车
{
        protected:引擎 engine;
        protected:轮胎 tyre[4];
}

The aggregation relationship is a kind of association relationship , which is a strong association relationship.
Aggregation is the relationship between the whole and the parts . For example, a car is composed of engines, tires, and other parts.
Reflecting that the whole and part can have different life cycles, it is a weak ownership relationship. For example, one wheel of a car can be broken and one can be replaced; the group of geese has big geese, and one big geese hangs , and the big geese will not disappear.

Comparison of inheritance and implementation

Inheritance: Hollow triangle solid line

Generalization relationship represents a class with the class between the inheritance , interfaces with the interface inheritance relationship between

Such as: the tiger is an animal, that tiger characteristics are also common animals.

Realization: Hollow triangle dotted line

To achieve a relationship, specify a contract between two entities . In other words, one entity defines a contract , and another entity guarantees the performance of the contract .

When modeling a Java application, the implementation relationship can be directly represented by the implements keyword.


UML class diagram, sequence diagram and use case diagram

UML class diagram

UML timing diagram

Timing diagram is a graph showing the interaction between objects , these objects are chronologically arrayed sequence diagram shown is involved in the interaction of objects and messages between object interaction sequence, a timing diagram modeling element includes a main There are: role (Actor), object (Object), lifeline (Lifeline), control focus (Focus of control), message (Message).
The following is the sequence diagram of the simple factory model:

UML use case diagram

 Use case diagrams mainly describe the relationship between "users, requirements, and system functional units".

It shows a system functional model diagram that can be observed by external users . Use case diagrams are mostly used in the static modeling phase (mainly business modeling and requirements modeling ) to help the development team understand the functional requirements of the system in a visual way .
 

Actor

In the system external to the Department of system interact directly with the person or thing.

Need to pay attention to the following two points:

  1. Participants are roles rather than specific people . They represent the roles that participants play in the process of dealing with the system. Therefore, in the actual operation of the system, an actual user may correspond to multiple participants in the system . Different users can also correspond to only one participant , thereby representing different instances of the same participant .
  2. Participants interact with the system as external users , which is its main feature. Represented by a villain

Use Case

A functional unit of the system visible outside the system. The functionality of the system provided the system unit , through a series of system functions can be with one or more participants expressed messages exchanged between. Expressed by an ellipse

After introducing the participants and use cases, we understand their relationship.

Association (Association)

Participants showing the interaction between the use cases , communication pathways, any one can be send or receive messages . A solid line with a normal arrow , the arrow points to the message recipient

Generalization

It is an inheritance relationship, the sub use cases and with the parent cases similar, but more particularly showing the behavior; sub use cases will inherit the parent embodiment with all structure, behavior and relationships . The child use case can use a behavior of the parent use case , or it can be overloaded.

The parent use case is usually abstract. Use a solid line with a triangular arrow , the arrow points to the parent class

Include

Used to decompose a more complex use case into smaller steps. It is necessary to include use cases .

If the include use case is missing , the base use case is incomplete and the include use case must be executed. Use a dashed line with an arrow and mark "include" to point to the functional use cases that are broken down

Extend

It is an extension of only the use case function , which is equivalent to providing an additional function for the basic use case.

The extended use case is optional . If the extended use case is missing , the integrity of the base use case will not be affected. Use a dotted line with an arrow and mark "Extension " to point to the base use case

 

Guess you like

Origin blog.csdn.net/as4589sd/article/details/112134000