# 8. Unified Modeling Language¶

## 8.1. UML Introduction¶

UML (Unified Modeling Language) is an ISO standardized method for describing programs. Its resulting diagrams are widely taught and should therefore be used as much as possible. The standard is mostly about the inner mechanism of the modeling language and not so much about the diagrams, however, the diagrams are the most useful part, as they are quickly understood even by non-programmers.

### 8.1.1. Getting Started with UML Diagrams¶

Check out these web-sites

This is the inheritance hierarchy of UML diagrams supported by PlantUML (clickable in HTML):

### 8.1.4. UML Tools¶

The site UML tools : Curated selection of free, online, OSS, for MAC,… tools is an extensive collection of UML tool information.

### 8.1.5. UML GUI Tools¶

Many UML tools specialize in providing a GUI environment to design diagrams with extensive support for a detailed standards-compliant specification of elements. The output is standardized but unreadable XMI (XML Metadata Interchange). This disqualifies most of the UML GUI tools for proper adhoc ASCII level documentation.

Creating unreadable diagram defintions, which require HTML/PDF/image generation before they become useful is highly undesirable if your focus is on programming. The incentive for a programmer to keep the documentation up to date is negative[1].

GUI Tools are still useful to explore the graphical notation of the various diagrams. See ref:gui tools with uml standard support.

### 8.1.6. Tools for Translating Declarative Specs to Diagrams¶

If your focus is on modeling, the UML GUI Tools are a better choice, but if your main task is programming, this is the way to go. The introduction to UMLGraph provides an excellent argument for declarative specification of UML diagrams.

The Stack Overflow question “Generating UML diagrams from textual representation” references a list of tools (Text to UML tools), but highlights PlantUML.

The PlantUML tool’s definition language is quite readable without the rendered diagrams. It also integrates with many tools (namely Emacs and Sphinx)- (See section Sequence Diagram). The GitHubGist generate PlantUML definition from python sources provides genclass.py, locally renamed to gen_plantuml.py. This command helps with the initial UML class diagrams and further updates. See section Auto generators for an example generator of a class diagram for global variables/functions.

yUML has sphinx integration, but is very limited in regarding readability and choice of diagrams (see section yUML).

Umple: Merging Modeling with Programming, i.e. it works as a programming language pre-processor (programming language extension, roundtrip).

## 8.2. UML Diagrams¶

The most important UML Diagrams are

### 8.2.1. Use Case Diagram¶

Use case diagrams are usually referred to as behavior diagrams used to describe a set of actions (use cases) that some system or systems (subject) should or can perform in collaboration with one or more external users of the system (actors). Each use case should provide some observable and valuable result to the actors or other stakeholders of the system. (https://www.uml-diagrams.org/use-case-diagrams.html)

Here is the use case diagram of a workers day:

.. uml::

@startuml
worker1   -> (work)
worker2   -> (work)
worker1   -> (home1)
worker2   -> (home2)
@enduml

This is how it is rendered in Sphinx:

For details see PlantUML Language Reference Guide.

### 8.2.2. Class Diagram¶

Class diagram is UML structure diagram which shows structure of the designed system at the level of classes and interfaces, shows their features, constraints and relationships - associations, generalizations, dependencies, etc. (https://www.uml-diagrams.org/class-diagrams-overview.html)

PlantUML example (PlantUML Language Reference Guide):

.. uml::

@startuml
class OneClass {
-private : string
+public : int
-priv_method()
+pub_method()
}
' stereotype
class TwoClass  << (I, #ffcccc) interface >>
OneClass ..|> TwoClass
hide TwoClass members
@enduml

This is how it is rendered in Sphinx:

#### 8.2.2.1. Associations between classes¶

UML association is relationship between classifiers to show that instances of classifiers could be either linked to each other or combined into some aggregation. See the definitive Guide to UML associations.
Association: is a relationship where all objects have their own lifecycle and there is no owner. Let’s take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers, but there is no ownership between the objects and both have their own lifecycle. Both can be created and deleted independently. is a specialised form of Association where all objects have their own lifecycle, but there is ownership and child objects can not belong to another parent object. Let’s take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department, the teacher object will not be destroyed. We can think about it as a “has-a” relationship. is again specialised form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child object does not have its lifecycle and if parent object is deleted, all child objects will also be deleted. Let’s take again an example of relationship between House and Rooms. House can contain multiple rooms - there is no independent life of room and any room can not belong to two different houses. If we delete the house - room will automatically be deleted. Let’s take another example relationship between Questions and Options. Single questions can have multiple options and option can not belong to multiple questions. If we delete the questions, options will automatically be deleted.

Source: StackExchange

PlantUML offers various association types:

Relation Symbol Description
Association -- no owner, navigability unspecified
Directed Association <-- no owner, navigable
Association x-- no owner, not navigable
Aggregation o-- owner, but independent
Composition *-- owner and dependent
Dependency <.. no owner
Generalization/Extension <│--
Realization <│..
Nesting +--

It is possible to replace -- by .. for broken lines.

#### 8.2.2.2. Class Diagram Examples¶

Naming conventions, visibility and types in global namespace and within classes:

Enums can be used to describe variable collections:

Here is a more elaborate class diagram in _static/big-brother.puml:

@startuml
!include ws-cartoon-logo.puml

## 8.6. Summary¶

• UML is the abbreviation of unified modeling language. It is a standarizied method for descriping programms.

• The UML diagrams are easy to understand even for noprogrammers

• There are existing some UML GUI-TOOLS. There are good for noprogrammers to modeling something, but programmers should’nt use them, because the not-diagram-output is’nt readable for a human. And if the output is not readable, it needs more effort to write or update a documentation (you would need every time this GUI-Tool if you want to know what happends in the programm via UML, without the GUI-TOOL, the output is worthless)

• Programmers should use PlantUML to create UML diagrams.

• PlantUML is a open source tool, which uses a certain syntax to create a UML diagram
• Programmers don’t need the diagram output, to get an accurate overview of the programm, because it is quite easy to understand the associations of the programm if you look at the PlantUML syntax
• PlantUML is already integrated in a lot of tools (for instance emacs, sphinx), so you can write your PlantUML code in for example in your python script as a commend, and emacs can show you the diagram with a shortcut.
• A class diagram (similar to entity relationship diagrams for databases) shows boxes for class, interface, annotation, enum, …

The upper section shows attributes, the lower section contains operations (methods).

• every class in it’s own box, globals in a own box
• different types of interfaces:
• Association – is independent (no owner) (students, teacher)
• Aggregation o– independent, no owner (department, teacher)
• Composition *__ death relationsship, if parent dies, all children will die too (kettle and tableau)
• Sequence Diagram

Shows the message flow between several participants of a system on timelines.

• Activity Diagram (in German known as “Aktivitätsdiagramm”)

### 8.6.1. Object diagram with dot(1)¶

Why dot(1) is not so useful for object diagrams.

 [1] As long as programmers maintain documentation, it will always be more or less out of date. When documentation is decoupled from a program it is nothing but guaranteed to be become incorrect.