Day 6 Class Diagram 2
Day 6 Class Diagram 2
Introduction
• A class diagram describes the types of objects
in the system and the various kinds of static
relationships that exist among them.
• Class diagrams also show the properties and
operations of a class and the constraints that
apply to the way objects are connected.
• Feature that covers properties and operations
of a class.
Classes
/ age : Date
Class Operations
Person
name : String
address : Address
birthdate : Date
ssn : Id
eat Operations describe the class behavior
sleep and appear in the third compartment.
work
play
Class Operations (Cont’d)
PhoneBook
Course
add(c : Course)
remove(c : Course)
Generalization Relationships
Person A generalization connects a
subclass to its superclass.
It denotes an inheritance of
attributes and behavior
from the superclass to the
Student subclass and indicates a
specialization in the subclass
of the more general superclass.
An abstract Shape Super
class {abstract} Class
Generalization
relationship
Circle Sub Class
Generalization Relationships (Cont’d)
Student Employee
TeachingAssistant
Association Relationships
Student Instructor
1..*
Association Relationships (Cont’d)
Student Instructor
1..*
Association Relationships (Cont’d)
membership
Student Team
1..* 1..*
Association Relationships (Cont’d)
member of
1..* 1..*
Student Team
1 president of 1..*
Association Relationships (Cont’d)
Router DomainNameServer
Association Relationships (Cont’d)
modelNumber
serialNumber
warrentyCode
Product Warranty
Association Relationships (Cont’d)
next
LinkedListNode
previous
Associations (cont.)
Role
name
Association
name
instructor
StaffMember Student
1..* instructs *
Role
Navigable
Multiplicity (uni-directional)
association * pre -
requisites
Courses
0..3
Reflexive
association
Association Relationships (Cont’d)
2..* 1..*
Car Door House
Whole Part
Association Relationships (Cont’d)
Scrollbar
1 1
Window Titlebar
1 1
Menu
1 1 .. *
Interfaces
<<interface>>
LinkedList List ArrayList
Interface Realization Relationship
<<interface>>
A realization relationship
ControlPanel connects a class with an
specifier
interface that supplies its
behavioral specification. It
is rendered by a dashed
line with a hollow
implementation
triangle towards the
VendingMachine
specifier.
Interfaces
inputStream
FileWriter
{file must not be locked}
FileReader
{file must exist}
outputStream
Parameterized Class
T A parameterized class or
LinkedList template defines a family of
potential elements.
To use it, the parameter must be
T bound.
1 .. *
A template is rendered by a small
dashed rectangle superimposed
on the upper-right corner of the
class rectangle. The dashed
rectangle contains a list of formal
parameters for the class.
Parameterized Class (Cont’d)
T
LinkedList
Binding is done with the
<<bind>> stereotype and a
T parameter to supply to the
1..* template. These are
adornments to the dashed
arrow denoting the
<<bind>>(Name)
realization relationship.
Exceptions can be
<<exception>>
Exception modeled just like any
other class.
getMessage()
printStackTrace() Notice the
<<exception>>
stereotype in the name
compartment.
<<exception>> <<exception>>
KeyException SQLException
Packages
A package is a container-like
element for organizing other
elements into groups.
Compiler A package can contain classes
and other packages and
diagrams.
Packages can be used to provide
controlled access between
classes in different packages.
Packages (Cont’d)
Compiler
FrontEnd BackEnd
Packages (Cont’d)
Compiler
FrontEnd BackEnd
Packages (Cont’d)
JavaCompiler Java
Constraint Rules and Notes
• Constraints and notes annotate among other
things associations, attributes, operations and
classes.
• Constraints are semantic restrictions noted as
Boolean expressions.
– UML offers many pre-defined constraints.
Customer 1 * may be
Order
{ total < $50 } canceled
id: long { value > 0 }
Constraint Note