Object-Oriented Programming

UML Class Diagrams

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

Communicating Class Design

  • Textual description
  • C++ code
  • UML Class

UML Diagrams

UML Class

  • A static, structure diagram
  • Name
  • Attributes - data members/fields
  • Operations - methods/member functions

Partial Meta-Object Facility (MOF)

Level Name Description Example
M2 metamodel UML Syntax Cat
M1 model UML Model
M0 data layer Real World Cat

Role of Classes

  • Classes represent the parts of the program
  • … they are entities, not actions
  • … PascalCase, e.g., Project, UndergraduateStudent
  • Operations are the actions of the class
  • … like free functions, they are in the verbTarget form
  • … typically use (at the model level) camelCase

Multiple Views


  • + public
  • - private
  • # protected
  • ~ package

UML Primitive Types

  • Integer
  • UnlimitedNatural
  • Real
  • Boolean
  • String

Attributes: visibility name:type multiplicity = default {property-string}

Attribute Syntax Description
+name public name
-name private name
-name:Name private name of type Name
-name:Name = "Project" private name of type Name with default "Project"
-name:Name[3] private name of type Name with multiplicity of 3
-name:Name = "Project" { persistent } private name of type Name with the default "Project", and property 'persistent'

Operations: visibility name(parameter-list):return-type {property-string}

Operator Syntax Description
+draw() public operator draw()
-draw() private operator draw()
#draw() protected operator draw()
+draw() : Boolean public operator draw() with return type Boolean
+draw() : Boolean {optional} public operator draw() with return type Boolean, and a property optional

Operation Parameters: direction name:type = default

Parameter Syntax Description
+draw(: Shape) parameter of type Shape
+draw(s: Shape) parameter s of type Shape
+draw(in shape : Shape) in parameter shape of type Shape
+draw(out picture : Picture) out parameter picture of type Picture
+draw(inout picture : Picture) inout parameter picture of type Picture

Parameter Directions in C++

C++ Declaration UML Parameter Direction
Shape in
const Shape& in
const Shape* in
Shape& inout
Shape& out
Shape* inout
Shape* out
Shape** out (typical API usage)



Multiplicity Syntax Description
* Any number of values
1 Single value (default)
0..1 No more than a single value
2..4 Two to four values

Multiplicity Terms

Multiplicity Term Description
Optional *
Mandatory 1..*
Single-valued 0..1
Multivalued 0..2, 0..*


  • stereotype is an extension mechanism to UML used as part of profiles
  • keyword is a formally defined stereotype
  • CBE - Control, Boundary, Entity

Static Attributes and Operations

  • No free functions in UML
  • Static operations do not have an object
  • Static attributes are shared among all objects of the class and can be used (in static operations) even without an object
  • Operations and attributes that are static are indicated in UML with an underline
  • Note: No parameters in UML does not mean there are no parameters. In this case, we don't care about that level of detail. The level of detail depends on the purpose of the model.

Static UML & C++


  • Use text to clarify diagram/design
  • The UML "comment" mechanism
  • No formal definition of note content


  • Attributes show the state of the objects and may not map directly into types in the implementation language
  • Show only the attributes and operations (methods) necessary for the given purpose
  • Public attributes typically map to get and set (stereotype) methods in the code
  • Only display constructors if needed

Forward Engineering: Model to Code

Reverse Engineering: Code to Model

UmlMode [Fowler]


  • UML to communicate an aspect of a system
  • forward engineering - sketches to work out design before implementation
  • reverse engineering - sketches for comprehension
  • Main feature: Selectivity
  • Requirements: Need to be performed quickly and collaboratively using a whiteboard or paper


  • Express design enough to hand off to another group
  • forward engineering - Every detail needed to implement the design
  • reverse engineering - Every detail of what design is in the code
  • Separation of labor: High-end designers versus "coders"
  • Main feature: Completeness


Current View

And, IMHO, the UML standard started going off the rails when some started morphing it to be a programming language with formal semantics. Visual representations are, by their very nature, abstractions, not precise representations.

Grady Booch (@Grady_Booch) June 30, 2018