Class Diagrams
TariffSchedule
Enumeration getZones()
Price getPrice(Zone)
*
*
Trip
zone:Zone
price:Price
Class diagrams represent the structure of the
system.
Class diagrams are used
• during requirements analysis to model problem domain
concepts
• during system design to model subsystems and
interfaces
• during object design to model classes.
Classes
Name
TariffSchedule
zone2price
getZones()
getPrice()
TariffSchedule
Table zone2price
Enumeration getZones()
Price getPrice(Zone)
Attributes
Signature
Operations
TariffSchedule
A class represent a concept.
A class encapsulates state (attributes) and behavior
(operations).
Each attribute has a type.
Each operation has a signature.
The class name is the only mandatory information.
Instances
tariff_1974:TarifSchedule
zone2price = {
{‘1’, .20},
{‘2’, .40},
{‘3’, .60}}
An instance represents a phenomenon.
• An object is an instance of a class.
The name of an instance is underlined and can contain the
class of the instance.
The attributes are represented with their values.
UML: Class and Instance
Diagrams
Inspector
joe:
Inspector
mary:
Inspector
Class Diagram
anonymous:
Inspector
Instance Diagram
Attributes and Values
Inspector
name:string
age: integer
joe:Inspector
name = “Joe”
age = 24
mary: Inspector
name = “Mary”
age = 18
Associations
TarifSchedule
Enumeration getZones()
Price getPrice(Zone)
TripLeg
*
*
price
zone
Associations denote relationships between
classes.
The multiplicity of an association end denotes
how many objects the source object can
legitimately reference.
1-to-1 and 1-to-Many
Associations
Country
name:String
Has-capital
1
1
City
name:String
1-to-1 association
Polygon
1
*
Point
x:Integer
y:Integer
draw()
1-to-many association
Aggregation
An aggregation is a special case of association
denoting a “consists of” hierarchy.
The aggregate is the class that contains the
components (embedded objects)
Exhaust System
1
Muffler
0..2
Tailpipe
Aggregation
Automobile
Engine
serial number
year
manufacturer
model
color
weight
horsepower
volume
on
off
drive
purchase
3,4,5
Wheel
diameter
number of bolts
*
Brakelight
on
off
2,4
Door
open
close
Battery
amps
volts
charge
discharge
Composition
A solid diamond denote composition, a strong
form of aggregation where components cannot
exist without the aggregate.
This is the “has-a” relationship in OOP
TicketMachine
3
ZoneButton
Generalization
Button
CancelButton
ZoneButton
Generalization relationships denote inheritance between
classes.
The children classes inherit the attributes and operations of
the parent class.
Generalization simplifies the model by eliminating
redundancy.
Names of abstract classes are usually italicized.
Inheritance
Models "kind of" hierarchy
Powerful notation for sharing similarities among classes
while preserving their differences
UML Notation: An arrow with a triangle
Cell
BloodCell
Red
White
MuscleCell
Smooth
Striate
NerveCell
Cortical
Pyramidal
From Problem Statement to Code
Problem Statement
A stock exchange lists many companies. Each company is
identified by a ticker symbol
Class Diagram
StockExchange
lists
*
*
Company
tickerSymbol
Java Code
public class StockExchange {
public Vector m_Company = new Vector();
};
public class Company {
public int m_tickerSymbol;
public Vector m_StockExchange = new Vector();
};
© Copyright 2026 Paperzz