The meaning of each symbol of the design pattern-UML class diagram

Source: Internet
Author: User
Tags dashed line



The meanings of the symbols of UML class diagrams
Class diagram basic symbols can be broken down into dashed lines, arrows, solid lines, hollow right triangles, solid right triangles, hollow diamonds and solid diamonds. These basic graphs are combined to form the basic symbols of the class diagram. It is important to note that the order of these symbols represents the degree of coupling between classes and classes. The more right coupling is higher.
Where the dashed + arrow is the relationship of dependence, the solid line + arrow indicates the relationship, the dashed + hollow right triangle represents the implements, the solid line + the hollow right triangle represents the generalization, that is, the inheritance relationship of the class. A solid + hollow diamond represents an aggregated relationship, while a solid + solid diamond represents a combined relationship.
Another point is to look at the class diagram when you should pay attention to. The idea of class diagram has not yet been divorced from object-oriented thought, centered on a certain class, some lines are injection and some lines are shot. The lines that are injected represent the lines that this class is called by which classes represent which classes are called by the class, including generalization, association, dependency, aggregation, and grouping of four relationships. This is similar to the description of the diagram section in discrete mathematics.
   1. Classes (Class): Represented by a three-layer rectangular box. The first layer displays the name of the class, and if it is an abstract class, it is displayed in italics. The second layer is the fields and properties. The third layer is the method of the class. Note that the preceding symbol, ' + ' means public, '-' denotes private, ' # ' represents protected.
   2. Interface: Using a two-layer rectangular box, the difference from the class diagram is primarily the <> display at the top. The first line is the interface name. The second line is the interface method.
   3. Inheriting classes (extends): Represented by a hollow triangle + solid line.
   4. Implementing the Interface (implements): Represented by a hollow triangle + dashed line
   5. Association (association): indicated by a solid arrow, for example: Swallow and climate
   6. Aggregation (Aggregation): Represents an aggregation with a hollow diamond + solid Arrow: Represents a weak ' owning ' relationship, which shows that a object can contain a B object, but the B object is not part of a object, for example: Company and employee combination (composition): a solid diamond + solid arrow to represent the composition: the relationship between the part and the whole, And the life cycle is the same. For example: Man and hand
   7. Dependency (Dependency): indicated by a dashed arrow, for example: animals and oxygen
   8. Cardinality: The numbers on both sides of the line indicate that the class at this end can have several instances, such as: A bird should have two wings. If a class can have countless instances, it is represented by ' n '. Associations, aggregations, and combinations are cardinality.

The relationships between classes


UML divides the relationship between classes into the following 5 types.
Association: There is a specific correspondence between Class A and instances of Class B
Dependency: Class A accesses the services provided by Class B
Aggregation: Class A is a global class, Class B is a local class, and the object of Class A is composed of objects of Class B
Generalization: Class A inherits Class B
Implementation: Class A implements the B interface
Association (Association)
Association refers to a particular correspondence between classes, represented by arrows with solid lines in UML. Depending on the number of classes, associations can be divided into the following three types:
One-to-one correlation
One-to-many associations
Many-to-many associations
Note: Associations also have to be divided into one-way and two-way associations
dependency (Dependency)
Dependency refers to the invocation relationship between classes, represented in UML with dashed arrows. If Class A accesses a property or method of Class B, or class A is responsible for instantiating Class B, then Class A relies on Class B. Unlike association relationships, you do not need to define Class B properties in Class A.
Aggregation (Aggregation)
Aggregation refers to the relationship between the whole and the part, which is represented in UML with a diamond-shaped arrow with a solid line. Aggregation relationships can also be divided into two types:
The clustered subsystem is allowed to be disassembled and replaced, which is a common aggregation relationship.
Clustered subsystems are not allowed to be disassembled and replaced, and this aggregation is called a strong aggregation relationship or a constituent relationship.
Note: Strong aggregation (composition) can be represented by a solid diamond-shaped arrow with solid lines.
generalization (generalization)





Generalization refers to the inheritance relationship between classes, which is represented in UML with a triangular arrow with solid lines. Implementation (realization) implementation refers to the relationship between a class and an interface, which is represented in UML with a dashed triangular arrow.



The following is a description of the GOF design pattern:
The arrows and triangles represent the subclass relationship.
A dashed arrow line indicates that one class instantiates an object of another class, and the arrow points to the class of the object being instantiated.
An ordinary arrow line indicates an acquaintance (acquaintance is also called an association or reference), meaning that an object knows only another object. Acquaintances may request each other's operations, but they are not responsible for each other, it only indicates a loosely coupled relationship between objects.
An arrow line with a diamond at the end represents an aggregation (aggregation), meaning that an object owns another object or is responsible for another object. Generally we call an object to contain another object, or a part of another object. Aggregation means that the aggregation object and its owner have the same life cycle.
Abstract class names are represented in italics, and abstract operations are also represented in italics. The diagram can include pseudo-code that implements the operation, and the code will appear in a box with a pleat, and a dashed line will connect the Pleat box to the operation implemented by the code.
   

That line represents a two-way association: Look to the left, flight plays the assignedfights role, and there are 0 to 1 plane associated with him (a flight either canceled without an airplane, or only one plane) to the right, plane plays the Assignedplane role, There are 0 or more flight associated with him (an aircraft can participate in multiple flights, can also be parked in the warehouse rotten)

The basic meaning is the same as above, the only difference is that the class on the right is ignorant of the class on the left.

The big bounding box is called a package, and the name is account, wrapping up some classes that can be categorized.

An arrow so dashed indicates that an interface is implemented.

The horizontal line is also a representation of the above-mentioned association, but an extension of the dashed lines from the associated wire, which means that when an instance of the flight class is associated to an instance of the Frequentflyer class, an instance of the Mileagecredit class is generated.

A diamond-shaped arrow represents a basic aggregation, by knowing that the wheel class plays the wheels role, aggregating 4 into the car object, the hollow diamond indicates that the wheel object is not created with the creation of the car, destroyed and destroyed

The meaning is similar to the above, the only difference is that the solid diamond represents the Department object created with the company object, destroyed and destroyed

Represents a reflection association that shows how an employee class is related to itself through the manager/manages role. When a class is associated with itself, this does not mean that an instance of the class is related to itself, but that one instance of the class is related to another instance of the class.

Design pattern-uml The symbolic meanings of the class diagram (GO)

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.