UML class diagram concise tutorial

Time:2021-8-29

UML class diagram is a graphical representation of object-oriented system for construction and visualization. Class diagram in Unified Modeling Language (UML) is a static structure diagram, which describes the system structure by displaying the system structure:

  • Class,
  • Their attributes
  • Operation (or method),
  • And the relationship between objects.

What is a class?


Classes are blueprints for objects. Objects and classes go hand in hand. We can’t talk about one without talking about the other. The focus of object-oriented design is not objects, but classes, because we use classes to create objects. Therefore, a class describes what an object will be, but it is not the object itself.

In fact, a class describes the type of an object, and an object is an available instance of a class. Each object is built from the same blueprint and therefore contains the same components (properties and methods). The standard meaning is that objects are classes and instances of objects – objects have state and behavior.

example

Dogs have state – color, name, breed and behavior – swing, bark, eat. An object is an instance of a class.

UML class diagram concise tutorial

UML class symbols


A class represents a concept that encapsulates the state(attribute)And behavior(operation)。 Each property has a type. eachoperationThere is oneautograph。_ The class name isUnique required information_。

UML class diagram concise tutorial

Class name:

  • The name of the class appears in the first partition.

Class attribute:

  • Properties are displayed in the second partition.
  • The property type is displayed after the colon.
  • Attributes map to member variables (data members) in code.

Class operation (method):

  • The actions are displayed in the third partition. They are the services provided by the class.
  • The return type of the method is displayed after the colon at the end of the method signature.
  • The return type of the method parameter is displayed after the colon after the parameter name. Operations are mapped to class methods in code

UML class diagram concise tutorial

Class visibility

The +, – and symbols in front of the property and operation names in the class represent the visibility of the property and operation.

UML class diagram concise tutorial

  • +Represents a public property or action
  • -Represents a private property or action
  • Represents a protected property or operation

Parameter directionality

Each parameter in an operation (method) can be expressed as in,outorinout, they specify the direction relative to the caller. The directivity is displayed before the parameter name.

UML class diagram concise tutorial

Perspectives of class diagram

The choice of perspective depends on how far you go in the development process. For example, in developingIn the process of domain model, you rarely surpassConceptual viewanalysis model UsuallyConceptual and normative perspectivesMixed together.Design modelDevelopment usually focuses onStart from normal angleAnd then evolved intoRealization angle

The diagram can be interpreted from a variety of perspectives:

  • Conceptual: represents concepts in the domain
  • Specification: focus on the interface of abstract data type (ADT) in software
  • Implementation: describes how a class will implement its interface

Perspective affects the amount of detail to provide and the kind of relationship worth presenting. As mentioned above, the class name is the only required information.

UML class diagram concise tutorial

Relationships between classes


UML is more than just beautiful pictures. If used correctly, UML can accurately convey how to implement code from diagrams. If interpreted accurately, the implemented code will correctly reflect the designer’s intention. Can you describe the meaning of each relationship relative to your target programming language, as shown in the figure below?

If you don’t recognize them yet, this section won’t help you understand UML class relationships. One class may involve one or more relationships with other classes. Relationships can be one of the following types:

UML class diagram concise tutorial

Inheritance (or generalization):

Generalization is the taxonomic relationship between more general classifiers and more specific classifiers. Each instance of a particular classifier is also an indirect instance of a general classifier. Therefore, specific classifiers inherit the characteristics of more general classifiers.

  • Indicates a “yes” relationship.
  • Abstract class names are shown in italics.
  • Subclass1 and subclass2 are the specialties of superclasses.

The following figure shows an example of an inheritance hierarchy. Subclass1 and subclass2 are derived from superclass. The relationship is displayed as a solid line with a hollow arrow pointing from the child element to the parent element.

UML class diagram concise tutorial

Inheritance example – shape

The following illustration shows an example of inheritance with two styles. Although connectors are drawn differently, they are semantically equivalent.

UML class diagram concise tutorial

Association

Association is the relationship between classes in UML class diagram. They are represented by solid lines between classes. Associations are usually named with verbs or verb phrases that reflect the real-world problem domain.

Simple association

  • A structural link between two peer classes.
  • There is an association between Class1 and class2

The following figure shows an example of a simple association. There is an association connecting < < control > > class Class1 and < < boundary > > class class2. The relationship is displayed as a solid line connecting the two classes.

UML class diagram concise tutorial

Cardinality

The cardinality is expressed as:

  • one-on-one
  • One to many
  • Many to many

UML class diagram concise tutorial

Aggregation

A special type of association.

  • It represents a “part” of the relationship.
  • Class2 is part of Class1.
  • Many instances of class2 (represented by *) can be associated with Class1.
  • Objects of Class1 and class2 have separate lifetimes.

The following figure shows an example of aggregation. The relationship is shown as a solid line with an unfilled diamond at the end of the association, which is connected to the class representing aggregation.

UML class diagram concise tutorial

Composition

  • A special aggregation in which a part is destroyed when the whole is destroyed.
  • The objects of class2 live and die together with Class1.
  • Class2 cannot stand on its own.

The following figure shows an example of the composition. The relationship is shown as a solid line with a solid diamond at the association end, which is connected to the class representing the whole or composition.

UML class diagram concise tutorial

Dependency

An object of one class may use an object of another class in the code of a method. If the object is not stored in any fields, it is modeled as a dependency.

  • A special type of association.
  • If a change to the definition of one class may result in a change to another class, the class exists between two classes (and vice versa).
  • Class1 depends on class2

The following figure shows an example of a dependency. The relationship is displayed as a dashed line with an open arrow.

UML class diagram concise tutorial

The following figure shows another example of a dependency. The person class may have a hasread method with a Book parameter, which returns true if the person has read the book (possibly by checking some databases).

UML class diagram concise tutorial

Realization

An implementation is the relationship between a blueprint class and an object that contains the details of its respective implementation level. It is said that this object implements the blueprint class. In other words, you can understand it as the relationship between the interface and the implementation class.

For example, the owner interface can specify methods to get and dispose of properties. The person and Corporation classes need to implement these methods in potentially completely different ways.

UML class diagram concise tutorial

Class diagram example: order system

UML class diagram concise tutorial

Class diagram example: Gui

Class diagrams may also have annotations attached to classes or relationships.

UML class diagram concise tutorial

Find free class diagram tools?


Visual paradise online freeIs a free online drawing software, supporting class diagrams, other UML diagrams, ERD tools and organization chart tools. It has a simple but powerful editor that allows you to create class diagrams quickly and easily. The free UML editor has no advertising, no access deadline, and no restrictions, such as the number of charts, shapes, etc. You have charts created for personal and non-commercial purposes.

UML class diagram concise tutorial

Quickly draw class diagram

Free UML software

Free class diagram for personal use:

  • Unlimited charts and shapes
  • Unlimited access time
  • No advertising

Draw any number of charts. Export graphics to PNG / JPG / GIF / SVG / PDF.

Simple and powerful

UML diagrams can be simple and interesting. Here are some features of our class diagram editor:

  • Drag to create a shape
  • Well connected connector (no separation)
  • Inline editing class properties and operations
  • Draw your own picture with your own shape
  • Hundreds of chart examples and templates

An impressive picture

Use the alignment wizard to precisely position the shape. Use a series of formatting tools to format class diagrams: shape and line format, font style, rotatable shape, shape alignment and distribution, embedded image and URL, shadow effect, etc

Class diagram (37 templates)

UML class diagram concise tutorial

Star LAN

UML class diagram concise tutorial

Token ring based LAN

UML class diagram concise tutorial

Company structure

UML class diagram concise tutorial

Understanding relationships

UML class diagram concise tutorial

File output (inductive use)

UML class diagram concise tutorial

Telephone (for association use)

UML class diagram concise tutorial

GOF design pattern – agent

UML class diagram concise tutorial

GOF design pattern Flyweight

UML class diagram concise tutorial

GOF design pattern – facade

UML class diagram concise tutorial

GOF design pattern – decorator

UML class diagram concise tutorial

GOF design pattern – Composite

UML class diagram concise tutorial

GOF design pattern – bridge

UML class diagram concise tutorial

GOF design pattern – adapter

UML class diagram concise tutorial

GOF design pattern – singleton

UML class diagram concise tutorial

GOF design pattern – Prototype

UML class diagram concise tutorial

GOF design pattern – plant approach

UML class diagram concise tutorial

GOF design pattern – generator

UML class diagram concise tutorial

GOF design pattern – Abstract Factory

UML class diagram concise tutorial

GOF design pattern – visitors

UML class diagram concise tutorial

GOF design pattern template method

UML class diagram concise tutorial

GOF design pattern – Strategy

UML class diagram concise tutorial

GOF design mode – Status

UML class diagram concise tutorial

GOF design pattern – observer

UML class diagram concise tutorial

GOF design pattern memento

UML class diagram concise tutorial

GOF design pattern – mediator

UML class diagram concise tutorial

GOF design pattern – iterator

UML class diagram concise tutorial

GOF design pattern – interpreter

UML class diagram concise tutorial

GOF design mode – commands

UML class diagram concise tutorial

GOF design pattern – responsibility chain

UML class diagram concise tutorial

Class diagram – ordering process

UML class diagram concise tutorial

Class diagram – constraints on classes and packages

UML class diagram concise tutorial

Class diagram – class in package (airline)

UML class diagram concise tutorial

sell ticket

UML class diagram concise tutorial

Self association

UML class diagram concise tutorial

Association level and self association

UML class diagram concise tutorial

Sales order system

UML class diagram concise tutorial

vehicle