Class diagram

Class diagram

the class diagram is a diagram used in software engineering to present the classes and interfaces of systems as well as the different relationships between them. A class describes the responsibilities, behavior, and type of a set of objects. The elements of this set are the instances of the class.

A class is a set of functions and data (attributes) that are linked together by a semantic field. Classes are used in object oriented programming. They make it possible to model a program and thus to split a complex task into several small simple jobs.

The classes can be linked together thanks to the inheritance mechanism which makes it possible to highlight kinship relations. Other relationships are possible between classes, each of these relationships is represented by a specific arc in the class diagram.

Diagram of a class

A class is represented by a rectangle separated into three parts:

  1. the name of the class: it is written in "Roman" font, abstract classes are written in italics or between <<__>>. Template classes have a rectangle with a dotted border in their upper right corner (see image below).
  2. the attributes of the class
  3. the methods of the class

uml class diagram


The syntax of an attribute is as follows: Visibility attributeName [multiplicity] : typeAttribute = Initialization;

The notion of visibility indicates who can have access to the attribute, it can take four values:

  • +: all the other classes have access to this attribute (public access).
  • #: only the class and its inheritance have access to this attribute (protected access).
  • ~: class visible only in the package.
  • -: only the class itself has access to this attribute (principle of encapsulation with getter and setter).

The attribute name must not contain spaces, punctuation marks or accents. The multiplicity represents the number of times the variable can exist for an object of the class.


An association is a relationship between two classes. It is described using:

  • of roles from an object of one class to an object of another (omitted if obvious);
  • of cardinalities, that is to say of numbers of objects of one class in an object of the other class; we use for that the notations:
    • 1 usually omitted if 1 to 1
    • not unknown at time of compilation, but narrow-minded
    • 0..n between 0 and n
    • 1..* 1 or more
    • * 0 or more
  • a relationship type oriented;
  • optionally constraints on the association.

The types of relationships frequently encountered are:

  • Inheritance

uml inheritance class diagram

  • The inner class

uml class diagram inner class

  • The addiction

dependency uml class diagram

  • Aggregation

uml class diagram aggregation

  • The composition

composition uml class diagram


example class diagram

To share