Software Engineering Methodologies

UML Class Diagram

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

Communicating Class Design

  • Could use text
  • Could use code
  • UML Class Diagram shows an overview of essential classes in a system and (more importantly) the relationship between them

UML Diagrams

UML Class

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

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
  • camelCase typically used (at model level)

Multiple Views

Visibility

  • + 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

Directions: in, out, inout

Parameter Directions in C++

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

[Sutton'05]

Multiplicity

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..*

Mapping Multiplicity to C++

Multiplicity Standard C++ Data Structures
Multivalued std::vector<int>, std::deque<int>, std::list<int>, std::array<int, n>
Single-valued std::optional<int> (C++14)

Guidelines

  • 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) important for the given purpose
  • Public attributes typically map to get and set (stereotype) methods in the code
  • Only display constructors if needed

Properties: Attributes & Association

  • Another notation for property (alternative to attribute)
  • Use attributes for properties that are data types, e.g., primitive types or whatever is considered a data type in your design
  • Use associations for class types, especially if the methods are of interest at the design level
  • Is String a class or a datatype?

 

DataType Class
Primitives Objects
Methods are familiar Methods are not familiar
Operators do not change Operators can change
New developers know exactly what you mean New developers have only a vague idea
Tend to be scalar (single value) Tend to be complex types
Equivalent values ⇨ same identity Two distinct objects can have the same value
Probably not a base for generalization (inheritance) Maybe a base for generalization (inheritance)

Stereotypes

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

Qt

Notes

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

Guidelines

  • 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) important for the given purpose
  • Public attributes typically map to get and set (stereotype) methods in the code
  • Only display constructors if needed

Forward Engineering

Reverse Engineering