Why do we need UML? Or how to save your nerves and time

Many programmers, faced with a difficult task, neglect the design phase, referring to the fact that design is a waste of time, and in this case it will only bother me.

Often this statement turns out to be true if the task is really small and the programmer’s qualifications are enough to determine the most optimal solution.

Programmers who do not use UML are divided into several groups:

  • I’ll start writing code, and in the process I’ll understand what and how;
  • I read forums, Habr, medium, stack overflow, a book, notes on the walls, signs over ...;
  • I ask my colleagues, maybe someone knows how to solve a similar problem;
  • I’ll start to draw small squares and schematically show what vision of the problem has formed in my mind.

But when solving more complex problems, advance planning and modeling greatly simplify programming. In addition, making class diagram changes is easier than making the source code.

You can draw an analogy with building a house. When someone wants to build a house, he does not just hit with a hammer and gets to work. He needs to have a plan - a design plan, so that he can analyze and modify his system.

If you have already begun to describe your task on paper, this is already a huge plus.

What is UML?

The official definition from Wikipedia.
UML  - Unified Modeling Language - is a notation system that can be used for object-oriented analysis and design. It can be used for visualization, specification, design and documentation of software systems.
Simply put, if you look at pictures in search engines, it will become clear that UML is something about schemes, arrows and squares.

It is important that UML translates as Unified Modeling Language. The main word here is Unified. That is, our pictures will be understood not only by us, but also by others who know UML. It turns out that this is such an international language for drawing circuits.

Pros and Cons of UML Design


  • waste of time;
  • the need for knowledge of various diagrams and their notations.


  • an opportunity to look at a task from different points of view;
  • other programmers find it easier to understand the essence of the task and how to implement it;
  • diagrams are relatively easy to read after quickly becoming familiar with their syntax.

In order to figure out if you need to use UML, you need to consider the main diagrams. Thanks to them, the overall picture is formed, giving an idea of ​​the possibilities of expressing architectural ideas in the framework of business tasks.

All the diagrams below are interconnected. By combining them, we can achieve the required level of decomposition of individual tasks.

I propose to get acquainted with some of the most useful and frequently used charts.
We will talk about diagrams of sequences, states, activities, and the most complex of them - class diagrams.

First I <...>, and then <...>, and then ... Sequence diagram

Imagine that you need to describe the sequence of actions for ordering goods in an online store. Who should be involved in the process? What phases does an order go through before it is placed?

Usually, we write a long list of stages that the application must go through in order to receive the proud status of “Decorated”. Then we describe who exactly will perform the specific action. And only after that we begin to program.

What is the disadvantage of this approach? He is not visual.

Imagine, before you lies a long list of the steps described earlier and comments on them. How easy will it be for you to figure it out? How long can it take? I guess that's enough.

An alternative to this approach is to use the sequence diagram shown in the figure below.

Sequence diagram The

characters are displayed at the top, and each arrow is a specific action associated with them. Learn more about this chart here.

State diagram. We configure old electronic clocks

The state diagram allows you to describe the behavior of an individual object under certain conditions. She will also show us all the possible states in which the object may be, as well as the process of changing states as a result of external influence.

Suppose we program a Soviet electronic clock.

To configure, we are given only a few buttons. Pretty sparse. At the same time, we know that one of the buttons switches the clock setting mode. Another button in the first mode changes minutes, and in the second hours.

The setup instruction is already quite small, but thanks to the state diagram, it is visually perceived much easier.

State diagram

Read more about the state diagram here .

Class diagram, or how to talk about your code without code

Class diagrams are used most often in modeling PS. They are a form of static description of the system from the point of view of its design. The class diagram does not display the dynamic behavior of the objects of the classes depicted on it. Class diagrams show classes, interfaces, and the relationships between them.
In various documentation, the description of design patterns, as well as reading the Habr, we all often come across a class diagram. Why is it used so often?

Suppose you need to design a system. Before embarking on the implementation of several classes, you will want to have a conceptual understanding of the system — what classes do I need? What functionality and information will these classes have? How do they interact with each other? Who can see these classes? Etc.

This is where class diagrams appear. Class diagrams are a great way to visualize classes on your system before you start coding them. They are a static representation of the structure of your system.

It is the class diagram that gives us the most complete and detailed idea of ​​the structure and relationships in the program code. Understanding the principles of constructing this diagram allows you to briefly and transparently express your thoughts and ideas.

Let's consider how to describe the well-known design pattern “Visitor” using the class diagram.
“Visitor” is a behavioral design pattern that allows you to add new operations to the program without changing the classes of objects on which these operations can be performed.

Class diagram

The most significant advantages of this diagram are:

  • saving time when explaining the task to other programmers;
  • more accurate and visual representation of the structure of the main elements of the system.

The disadvantages include significant time costs, provided that there is a lack of experience with this diagram.

You can read more about the class diagram here , and about the Visitor pattern here .

Activity chart

An activity diagram  is a technology that allows you to describe the logic of procedures, business processes, and workflows. In many cases, they resemble flowcharts, but the fundamental difference between activity diagrams and the notation of flowcharts is that the former support parallel processes.
In short, the activity diagram helps us describe the logic of system behavior. It is possible to build several activity diagrams for the same system, each of which will focus on different aspects of the system, show different actions that are performed inside it.

It is on the activity diagram that shows the transitions from one activity to another. This, in fact, is a kind of state diagram, where all or most of the states are some activities, and all or most of the transitions work when a certain activity is completed and allow you to proceed to the next one.


diagram The meaning of the diagram is understandable. It shows how to work with a web application that solves a certain problem in a remote database. Pay attention to the arrangement of activities in this diagram: they are, as it were, scattered in three columns, each of which corresponds to the behavior of one of the three objects - the client, the web server and the database server. Thanks to this, it is easy to determine which of the objects performs each of the activities.

You can read more about the activity diagram here .


Hopefully after this article you take a different look at UML. Now, when reading literature or sites devoted to this topic, it will be easier for you to understand what the purpose of UML and to find opportunities for its application. Try to start applying it and you will feel all the strength and power hidden behind a set of arrows and squares.

Leave a comment if you think (or know) that something is wrong or could be described better.

Also popular now: