The article directories

  • UML
  • The class diagram
    • Rely on
    • generalization
    • implementation
    • associated
    • The aggregation
    • combination
  • How do I draw a class diagram?
    • Environment to prepare
      • Install Graphviz
      • Install PlantUML
    • PlantUML
      • define
      • methods
      • Relationship between
      • annotation
  • Afterword.

UML


UML(Unified Modeling Language) is a standard Language for the specification, visualization, and documentation of products of object-oriented systems. It is a non-patented third generation Modeling and specification Language. UML is a modeling tool for object-oriented design, independent of any specific programming language. Easy communication between programmers, reading other people’s code is a real pain.

  • UML has the following functions:
  1. Create visual models for software systems
  2. Build the components for the software system
  3. Document the software system
  • Classification of UML diagrams:
  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

Among them, class diagram, which describes the relationship between classes, is the most core UML diagram. This paper will expand and introduce class diagram based on PlantUML. Use Case diagrams and sequence Diagrams: UML use case diagrams and sequence diagrams: PlantUML practice sharing

The class diagram


The Class diagram shows the static structure of the model, especially the existing classes in the model, the internal structure of the classes and their relationship with other classes. Class diagrams do not display transient information. Class diagrams are an important part of object-oriented modeling. It is used for both general conceptual modeling of the system classification of applications and for detailed modeling, transforming the models into programming code. Class diagrams can also be used for data modeling.

  • Relationships between classes: dependencies, generalization (inheritance), implementation, association, aggregation, and composition.

Rely on

As long as each other is used in a class, there is a Dependency relationship between them. You can’t even get through the stream without the other side. Such as

  1. Class uses each other
  2. Is a member property of a class
  3. Is the return type of the method
  4. Is the type of argument received by the method
  5. Method

generalization

generalizationRelations are Generalization relations, which are actually inheritance relations and special cases of dependencies. If class A inherits class B, then A and B have Generalization relations.

implementation

implementationA Realization is, in effect, the relationship between a class and an interface, indicating that a class is an implementation of all the characteristics and behaviors of the interface and a special case of the dependency.

associated

associatedAssociation is actually a relation between classes. It is a kind of owning relation, which enables one class to know the properties and methods of another class. It is also a special case of dependency relation.

Associations are navigational: bidirectional or unidirectional, or they can be unidirectional. A two-way association can have two arrows or no arrows, and a one-way association has one arrow. No nm, 1N, etc.

The aggregation

The aggregationAggregation means the relationship between the whole and the parts,The whole can be separated from the parts, the part can be separated from the whole and belong to the special case of correlation. The navigation can be marked by arrows and represented by solid lines with hollow diamonds:

combination

combination“Composition” is also the relationship between the whole and the parts, butThe whole cannot be separated from the parts, the part can exist independently from the whole and is a special case of association. The navigation can be marked by arrows and represented by solid lines with solid diamonds:

How do I draw a class diagram?


With all that said, how do you draw a class diagram? And keep reading.

Environment to prepare

If you don’t want to install PlantUML, you can also use PlantUML online and skip this section.

Install Graphviz

The first step is to install Graphviz visual graphics software to provide dependency support.

  1. download

    Www2.graphviz.org/Packages/de…

  2. The installation

    Note to modify the installation path, the rest of the default next step is fine.

  3. Configuration variables

    My Computer -> Properties -> Advanced System Settings -> Environment Variables -> Path -> New











4. Test

Install PlantUML

Go to IDEA, File-> Settings ->plugins, search for UML, and install PlantUML



After installing, restart IDEA to create PantUML File.



PlantUML


define

If not defined, use it directly, default to class.

type The keyword legend
class class
An abstract class abstract
interface interface
interface Lollipop style
The enumeration enum
annotation annotation
The generic Add <? . >

methods

Scope of access symbol
private
protected #
package private ~
public +

You can also define static, abstract methods or properties using the {static} and {abstract} modifiers.



Relationship between

Arrow ‘>’ said, ‘|’ > ‘said triangular arrowheads,’ o ‘said hollow diamond,’ * ‘said solid diamond’. ‘said the dotted line,’ – ‘said solid lines, one is horizontal, is more than two vertical direction.

  • Identification on relationships When using labels between relationships, use: followed by label text; For elements, you can use “” on each side.

So now you have lines that represent all kinds of relationships.

Relationship between symbol legend
Rely on . >
generalization ->
implementation . | >
associated
The aggregation -o
combination – *

annotation

  • Note left of, note right of, note top of, note bottom of can be used to add notes
  • Note left, note right,note top, note bottom can also be added at the end of the class declaration
  • The note keyword alone can also be used, using… A symbol may draw a dotted line connecting it to other objects

Afterword.


More details and extensions for drawing class diagrams can be found in the PlantUML documentation: plantuml.com/zh/class-di…

For example, I did not execute the “dot-c” command when INSTALLING Graphviz, idea reported an error and the whole website could not be found. I started to give up. UML Use case diagrams and sequence diagrams: PlantUML Practice sharing

Original is not easy, please do not reprint (this is not rich visits add insult to injury) blogger home page: blog.csdn.net/qq_45034708 If the article is helpful to you, remember to focus on the likes collection ❤