Master UML class diagram generation in one article: Practical sharing of PlantUML plug-in in IDEA

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:
  1. Build a visual model for the software system
  2. Build components for the software system
  3. Document the software system
  • UML diagram classification:
  1. Use case diagram
  2. Static structure diagram: class diagram , object diagram, package diagram, component diagram, deployment diagram
  3. 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

  1. Each other is used in the class
  2. Is a member attribute of the class
  3. Is the return type of the method
  4. Is the parameter type received by the method
  5. Used in the method

Insert picture description here

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.
Insert picture description here

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.
Insert picture description here

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.
Insert picture description here

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:
Insert picture description here

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:
Insert picture description here

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.

  1. Download
    https://www2.graphviz.org/Packages/development/windows/10/
    Insert picture description here
  2. Installation
    Pay attention to modify the installation path, the rest is the next step by default.
    Insert picture description here
  3. Configuration Variables
    My Computer->Properties->Advanced System Settings->Environment Variables->path->New
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here
    Insert picture description here

M0NzA4,size_16,color_FFFFFF,t_70#pic_center)
4. Testing
Insert picture description here

Install PlantUML

Open IDEA, File->settings->plugins, search for uml, install PlantUML
Insert picture description here
and restart IDEA after installation, you can create a new PantUML File.
Insert picture description here
Insert picture description here

PlantUML


definition

If it is not defined, use it directly. The default is the class.

Types of Keyword legend
class class Insert picture description here
Abstract class abstract Insert picture description here
interface interface Insert picture description here
interface Lollipop style Insert picture description here
enumerate enum Insert picture description here
Comment annotation Insert picture description here
Generic Add <?..> Insert picture description here

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}.
Insert picture description here
Insert picture description here

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 .> Insert picture description here
Generalization -> Insert picture description here
achieve .|> Insert picture description here
Related - Insert picture description here
polymerization -The Insert picture description here
combination -* Insert picture description here

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
    Insert picture description here

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 do not 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 ❤

Guess you like

Origin blog.csdn.net/qq_45034708/article/details/108661399
Recommended