Article Directory
UML
The UML ( the U- nified M odeling L anguage, Unified Modeling Language ) is an object-oriented system for the products will be described, a standard language for creating documentation and visual, non-proprietary and third generation specification language modeling. UML is a modeling tool for object-oriented design, independent of any specific programming language.
It is convenient for programmers to communicate, and reading other people's code is really painful.
- UML mainly has the following functions:
- Build a visual model for the software system
- Build components for the software system
- Document the software system
- UML diagram classification:
- Use case diagram
- Static structure diagram: class diagram , object diagram, package diagram, component diagram, deployment diagram
- Dynamic behavior diagram: interaction diagram (sequence diagram and collaboration diagram), state diagram, activity diagram
The class diagram describes the relationship between classes and is the core of the UML diagram. This article will introduce the class diagram in conjunction with PlantUML. If the article has more than 100 praises, other UML diagram categories will be updated .
Class Diagram
FIG class (Class diagram) is a static structure of the model, especially in the presence of model classes, the internal structure of classes and their relationships to other classes, and the like. The class diagram does not display temporary information. Class diagram is the main component of object-oriented modeling. It is used not only for general conceptual modeling of the system classification of applications, but also for detailed modeling, converting the model into programming code. Class diagrams can also be used for data modeling.
- The relationship between classes: dependency, generalization (inheritance), realization, association, aggregation and composition.
rely
As long as the other party is used in the class, there is a dependency relationship between them. If there is no other party, even the edited version will not pass. such as
- Each other is used in the class
- Is a member attribute of the class
- Is the return type of the method
- Is the parameter type received by the method
- Used in the method
Generalization
Generalization relationship (the Generalization) actually is inherited, a special case of a dependency, if A class inherits class B, then A generalization relationship exists and B.
achieve
Realization relationship (Realization) is actually the relationship between classes and interfaces, represent the class is the interface to achieve all of the features and behavior, but also the special case of dependent relationship.
Related
Association (Association) is actually the connection between the class and the class. It is a kind of ownership relationship. It makes one class know the properties and methods of another class, and it is also a special case of the dependency relationship.
Associations are navigable : they are two-way or one-way relationships, or they can be one-way. Two-way associations can have two arrows or no arrows, and unidirectional associations have one arrow. Marks such as nm and 1n are optional.
polymerization
Polymerization relationship (Aggregation) and the overall relationship is represented by portion, integral with the portions may be separated , from the integral portion may exist separately, are associated with the exception, identifying the available navigational arrow, a solid line with open diamonds represented:
combination
The composition relationship is also the relationship between the whole and the part, but the whole and the part cannot be separated , and the part can exist separately from the whole. It is a special case of association. It can be used to indicate navigation by arrows and use a solid line with a solid diamond to indicate:
How to draw a class diagram?
Having said that, how to draw a class diagram? And continue to look down.
Environmental preparation
Install the PlantUML plug-in in IDEA for the operation exercise. Of course, if you don’t want to install it, you can also use the PlantUML online website and skip this section .
Install Graphviz
First, you need to install Graphviz visual graphics software to provide dependent support.
- Download
https://www2.graphviz.org/Packages/development/windows/10/
- Installation
Pay attention to modify the installation path, the rest is the next step by default.
- Configuration Variables
My Computer->Properties->Advanced System Settings->Environment Variables->path->New
4. Testing
Install PlantUML
Open IDEA, File->settings->plugins, search for uml, install PlantUML
and restart IDEA after installation, you can create a new PantUML File.
PlantUML
definition
If it is not defined, use it directly. The default is the class.
Types of | Keyword | legend |
---|---|---|
class | class | |
Abstract class | abstract | |
interface | interface | |
interface | Lollipop style | |
enumerate | enum | |
Comment | annotation | |
Generic | Add <?..> |
method
Access range | symbol |
---|---|
private | - |
protected | # |
package private | ~ |
public | + |
In addition, static and abstract methods or properties can be defined through modifiers {static} and {abstract}.
relationship
'>' means arrow,'|>' means triangle arrow,'o' means hollow diamond,'*' means solid diamond
'.' means dashed line,'-' means solid line, one is horizontal, two or more are vertical Straight direction.
- Identification
on the relationship When using labels to illustrate between relationships, use: followed by the label text;
for element descriptions, you can use "" on each side to illustrate.
In this way, lines of various relationships can be represented.
relationship | symbol | legend |
---|---|---|
rely | .> | |
Generalization | -> | |
achieve | .|> | |
Related | - | |
polymerization | -The | |
combination | -* |
Comment
- You can use note left of, note right of, note top of, note bottom of these keywords to add notes
- You can also use note left, note right, note top, note bottom to add notes at the end of the class declaration
- It is also possible to use the keyword note alone. Use the ... symbol to make a dashed line connecting it with other objects
postscript
For more details and extensions of drawing class diagrams, please refer to PlantUML document: https://plantuml.com/zh/class-diagram
I stepped on a lot of pits. For example, when I installed Graphviz, I didn't execute the "dot -c" command, and the idea was reported on the whole network and I couldn't find it. From getting started to giving up .
If the article is praised and broken, other UML diagram categories will be updated.
The original is not easy, please
donot reprint (this is not a wealthy visits worse) the
blogger's homepage: https://blog.csdn.net/qq_45034708
If the article is helpful to you, remember to follow, like and collect ❤