Uml Class Diagram Cheat Sheet



The UML diagram is a powerful tool which lets visually represent all system's components, the interactions between them and relationships with external user interface. The Rapid UML solution for ConceptDraw DIAGRAM software offers diversity of UML flowchart symbols for drawing all types of UML diagrams. Class,” which can contain method and field definitions in addition to the abstract declarations.) My extension to UML: rounded corners identify interfaces. If the full interface specification is in some other diagram, I use: Strict UML uses the «interface» stereotype in the name compartment of a standard class.

Please note that you must enable JavaScript if you want larger <code> blocks to be highlighted.

The Unified Modeling Language (UML) includes interaction diagrams with the purpose to illustrate how objects interact via messages. Interaction diagrams are used for dynamic object modelling. There are two common types: sequence and communication diagrams. Communication diagrams illustrate the interactions between objects in terms of sequenced messages. In this blogpost I will provide you with an overview of basic communication diagram notations and common patterns. You should this blogpost as a cheatsheet.

Content

Links

A link is a connection path between to objects—it is an instance of an association. Note that multiple messages and messages in both ways flow along the same—single—link.

Messages

Each message between objects is represented with a message expression and small arrow indicating the direction of the message. The best practise is to not number the starting message. However, even though it is legal to do, it simplifies the overall numbering if you do not do it.

Messages to itself

A message from an object to itself is illustrated by a link to itself, with messages flowing among the link.

Creation of instances

The UML convention is to use a message named `create` to create an instance. It is legal to use another message name. If you do use another message name, you can—and should—annotate the message with a UML stereotype, in this case `«create»`. Furthermore, you may optionally add the UML tagged value `{new}` to the lifeline box to highlight the creation.

Message number sequencing

The order of messages is illustrated with sequence numbers. As stated before, the best practise is to not number the starting message, because you would create another level of number-nesting deeper than otherwise necessary.

The order and nesting of subsequent messages is shown with a legal numbering scheme in which nested messages have a number appended to them. Note that you denote nesting by prepending the incoming message number to the outgoing message number.

Conditional messages

A conditional message is shown by following a sequence number with conditional clause in square brackets. The message is only sent if the clause evaluates to `true`.

Mutually exclusive conditional paths

With mutually exclusive conditional paths you must modify the sequence expressions with a conditional letter. By convention, the first letter used is `a`. The figure below states that either `1a` or `1b` could execute after `msg1`. Since either could be the first internal message, both are sequence number 1.

Iteration or looping

Iteration over a collection

Asynchronous calls

Asynchronous calls are shown with a stick arrow; synchronous calls with a filled arrow, see the figure below.

draw.io

All of above diagrams, are created with draw.io.

References

Larman, C. (2005). Applying UML and patterns: an introduction to object-oriented analysis and design and the unified proces (3th ed.) (pp. 240-247). Upper Saddle River (New Jersey): Pearson Education, Inc.

Relationships between classes

Uml class diagram software

UML is not just about pretty pictures. If used correctly, UML precisely conveys how code should be implemented from diagrams. If precisely interpreted, the implemented code will correctly reflect the intent of the designer. Can you describe what each of the relationships mean relative to your target programming language shown in the Figure below?

If you can't yet recognize them, no problem this section is meant to help you to understand UML class relationships. A class may be involved in one or more relationships with other classes. A relationship can be one of the following types:

Inheritance (or Generalization):

A generalization is a taxonomic relationship between a more general classifier and a more specific classifier. Each instance of the specific classifier is also an indirect instance of the general classifier. Thus, the specific classifier inherits the features of the more general classifier.

  • Represents an 'is-a' relationship.
  • An abstract class name is shown in italics.
  • SubClass1 and SubClass2 are specializations of SuperClass.

The figure below shows an example of inheritance hierarchy. SubClass1 and SubClass2 are derived from SuperClass. The relationship is displayed as a solid line with a hollow arrowhead that points from the child element to the parent element.

Uml Class Diagram Cheat Sheet Printable

Inheritance Example - Shapes

The figure below shows an inheritance example with two styles. Although the connectors are drawn differently, they are semantically equivalent.

Uml Class Diagram Cheat Sheet Download

Association

Associations are relationships between classes in a UML Class Diagram. They are represented by a solid line between classes. Associations are typically named using a verb or verb phrase which reflects the real world problem domain.

Simple Association

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

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

Cardinality

Cardinality is expressed in terms of:

Cheat
  • one to one
  • one to many
  • many to many
Uml class diagram java

Aggregation

A special type of association.

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

The figure below shows an example of aggregation. The relationship is displayed as a solid line with a unfilled diamond at the association end, which is connected to the class that represents the aggregate.

Composition

  • A special type of aggregation where parts are destroyed when the whole is destroyed.
  • Objects of Class2 live and die with Class1.
  • Class2 cannot stand by itself.

The figure below shows an example of composition. The relationship is displayed as a solid line with a filled diamond at the association end, which is connected to the class that represents the whole or composite.

Dependency

An object of one class might use an object of another class in the code of a method. If the object is not stored in any field, then this is modeled as a dependency relationship.

  • A special type of association.
  • Exists between two classes if changes to the definition of one may cause changes to the other (but not the other way around).
  • Class1 depends on Class2

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

Uml diagram implements

The figure below shows another example of dependency. The Person class might have a hasRead method with a Book parameter that returns true if the person has read the book (perhaps by checking some database).

Realization

Realization is a relationship between the blueprint class and the object containing its respective implementation level details. This object is said to realize the blueprint class. In other words, you can understand this as the relationship between the interface and the implementing class.

For example, the Owner interface might specify methods for acquiring property and disposing of property. The Person and Corporation classes need to implement these methods, possibly in very different ways.