that were shone when I got tempered!

Class Diagrams [Part 1/2] – Representing classes

leave a comment »

A Class diagram is made up with a set of classes and the relationship between them

Representation of a Classes in a class diagram.

Class is represented by a Box with separate partitions

  • Class Name : This is in the first partition.Screenshot from 2014-02-20 15:47:04
  • Instance Variables : This is in the second partition. Variable type is shown after the colon.
  • Methods : This is in the third partition. Method’s return type is provided after the colon at the end of the method signature. Argument type is provided after the colon at the end of the argument name. Method directionality is mentioned as in/out and inout. A reference to some class is denoted by an asterix (*).

If a class variable or a method is a static it must be underlined. And if Class or a method is abstract it should be italic.

In the picture, we can observe the following for MyClassName

  • MyClassName has 3 attributes and 3 operations
  • op2 returns a float
  • Parameter p3 of op2 is of type int
  • op3 returns a pointer (denoted by a *) to Class6

Visibility and Access for the variables and methods of the class diagram

Access levels are denoted by +, – and # signs preceded to the variable and method names.

  1. + denotes public attributes or operations
  2. – denotes private attributes or operations
  3. # denotes protected attributes or operations

Method parameter directionality

Screenshot from 2014-02-20 16:01:52

Each parameter in an operation (method) may be denoted as in, out or in/out which specifies its direction with respect to the caller. This directionality is shown before the parameter name.

Check this sample for more info.


How to mention the static, final properties in class diagrams (eg : Constants). – [10]

Constants can be simply mentioned using all caps notation as below

+ VAR_NAME : Type = "value".

If you need to mention the final, static properties of them you can further use the leaf, readonly attributes.

final definition, i.e. it cannot be overridden in sub-classes – this corresponds to the isLeaf property of the attribute:

isLeaf: Boolean – Indicates whether it is possible to further redefine a RedefinableElement. If the value is true, then it is not possible to further redefine the RedefinableElement. (UML Superstructure, p. 132)

There is no official notation for attributes with isLeaf=true, but adding “{leaf}” is common.

final value, i.e. its value cannot be changed – this corresponds to the isReadOnly property of the attribute:

isReadOnly : Boolean – If true, the attribute may only be read, and not written. The default value is false. (UML Superstructure, p. 125)
Notation for read-only attributes consists of appending “{readOnly}” to the attribute string.

constant usually refers to a non-changeable attribute of the class itself instead of an instance (static final attribute). In UML it would have both properties mentioned above and additionally be static, which corresponds to the isStatic property:

isStatic: Boolean – Specifies whether this feature characterizes individual instances classified by the classifier (false) or the classifier itself (true). Default value is false. (UML Superstructure, p. 69)


So, an constant can be mentioned as below.

+ FOO : String = "x" {readOnly,leaf}

Further, you can use steriotype <<final>> to mark method as final[11].


How to show the dependency injection in class diagrams.

With the arrow pointing from A to B, then this means A gets injected with a B [12]


References :


Written by Namal Fernando

February 20, 2014 at 7:31 am

Posted in Class Diagrams, UML

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Ruth's Reflections

Contemplations from quakey quirky Christchurch

TED Blog

The TED Blog shares interesting news about TED, TED Talks video, the TED Prize and more.


Learn and discover simple things

Meihta Dwiguna Saputra's Knowledge Base

~In learning you will teach and in teaching you will (re)learn~

The Java Blog

Thoughts, tips and tricks about the Java programming language


that were shone when I got tempered!

%d bloggers like this: