SlideShare a Scribd company logo
Class Diagrams
Introduction
• This session will cover:
– Class Diagrams
• Problem Domain
• Solution Domain
– Anatomy of a Class
– Relationships in Class Diagrams
• Generalisation (Inheritance)
• Aggregation
• Association
– Finer Points of Class Diagrams
• Polymorphism
• Package Diagrams
• Association Classes
Class Diagrams
• A class diagram in the UML is a static structure diagram that
describes the structure of a system by showing the system's
classes, their attributes, and the relationships between the
classes
• The class diagram is the main building block in object oriented
modelling
– They are being used both for general conceptual modelling of the
systematics of the application, and for detailed modelling translating
the models into programming code
– The classes in a class diagram represent both the main objects and or
interactions in the application and the objects to be programmed
• As such, class diagrams are a bridge between the problem and
solution domains
Class Diagrams in the Problem Domain
• The domain model is created in order to document the
key concepts, and the domain-vocabulary of the system
being modelled
• The model identifies the relationships among all major
entities within the system, and is often extended to
identify their important methods and attributes
• The domain model provides a structural view of the
system that can be complemented by other dynamic
views in Use Case models
Class Diagrams in the Problem Domain
• An important benefit of a domain model is that it
describes and constrains the system scope
• The domain model can be effectively used to verify
and validate the understanding of the problem
domain among stakeholders
• It is especially helpful as a communication tool and a
focusing point between technical and business teams
Class Diagrams in the Solution Domain
• The domain model is extended in the construction
phase of the software development cycle since the
semantics shown therein can be used in the source
code
• Entities can become classes, while the important
methods and attributes can be carried directly to the
source code
– Not all entities become classes, some are purely “domain
objects”
– Methods and attributes are often added to as additional
behaviour is required
Anatomy of a Class
• Each class is
represented as a box,
with three elements
– The upper part holds the
name of the class
– The middle part contains
the attributes of the
class
– The bottom part gives
the methods or
operations the class can
take or undertake
NamedClass
firstAttribute
secondAttribute
firstMethod
secondMethod
Shape
area
volume
getArea
getVolume
Anatomy of a Class
• In the domain model, little
detail is (initially) included
in an individual class
• As system design
progresses, detail is added
in terms of typecasting
attributes, defining whether
methods are public etc
– Private methods/attributes
are preceded by a –
– Public methods/attributes are
preceded by a +
– Protected methods/attributes
are preceded by a #
Shape
-area : int
#volume : double
+getArea()
#getVolume()
Relationships Between Classes
• The Class Diagram is used to represent many
relationships between entities (in the problem
domain) and classes (in the solution domain)
• The three major relationships are:
– Generalisation
– Aggregation (including Composition)
– Association
Generalisation (Inheritance)
• Generalisation is the ability to create a base class and
then derive classes from that base class
• Derived classes “inherit” the attributes and methods
of the base class
– Exceptions are dealt with through overriding
• Base classes that will never be used to create objects
and just allow the creation of a derived class is an
abstract class
Generalisation (Inheritance)
• Generalisation
relationships are
indicated using the
same notation as in Use
Case Diagrams
• An open arrow head
shows the
generalisation
Shape
area
volume
getArea()
getVolume()
Square
sideLength
setSideLength()
Circle
circleRadius
setRadius
getCircumference
No “set”
methods, this is
likely to be an
abstract class
The Shape class
is a
generalisation
of Circles and
Squares
Aggregation
• Aggregation is often referred to as the “whole-part”
relationship
– It can be considered a “has a…” relationship
Aggregation
• The aggregation
relationship is indicated
by a diamond icon next
to the “whole” class
• Arrowheads are used to
indicate directionality of
communication
– No arrowheads indicates
that communication is
bi-directional
Car
make
model
drive()
accelerate()
Transmission
changeGear()
Engine
increaseFuel()
drive() method
calls
changeGear()
method in
transmission
accelerate()
method calls
increaseFuel()
method in
engine
Composition
• Composition is a form of
aggregation
• In UML, composition is
depicted as a filled
diamond and a solid line
• It always implies a
multiplicity of 1 or 0..1, as
no more than one object
at a time can have
lifetime responsibility for
another object
Car
make
model
drive()
accelerate()
Engine
increaseFuel()
Aggregation & Composition
• Aggregation differs from composition in that it does
not imply ownership
– In composition, when the owning object is destroyed, so
are the contained objects
– In aggregation, this is not necessarily true
Generalisation & Aggregation
• Both Generalisation and
Aggregation can be
“layered” to what ever
extent is useful
Shape
Rectangle
Square
Generalisation & Aggregation
• Both Generalisation and
Aggregation can be
“layered” to what ever
extent is useful
Order
totalPrice
addLineItem()
LineItem
numberOfItems
totalPrice()
Item
price
Association
• The association relationship is simply a relationship
that means two classes “communicate”
• Often one class provides a service to another or one
class starts a series of events by executing a method
of another class
• Associations are drawn as lines/arrows connecting
classes
Association
• The line between
classes tells us
something about the
relationship
• In this example, there is
a uni-directional
relationship
– An object of ClassA can
call methods of an
object from ClassB, but
not vice-versa
ClassA
methodA()
ClassB
methodB1()
methodB2()
Association
• In this example, there is
a bi-directional
relationship
– An object of each class
can invoke methods in
objects of the other class
• In UML, bi-directional
relationships are not
modelled as double-
headed arrows but the
absence of arrows
ClassA
methodA()
ClassB
methodB1()
methodB2()
Cardinality
• Association and Aggregation relationships can be
further refined by defining the cardinality of the
relationship
– One to many, many to many, mandatory etc
• The following notation is used in UML
1 No more than one
0..1 Zero or one
* Many
0..* Zero or many
1..* One or many
Aggregation Example
• Each order object must
have at least one line
item object
• Each line item object
must belong to one
order
Order
totalPrice
addLineItem()
LineItem
numberOfItems
totalPrice()
Item
price
1
1..*
1
1..*
Association Example
• A specific object of
ClassA must have a
relationship with a
specific object of ClassB
• A ClassB object may
have a relationship with
any number of ClassC
objects
– And vice-versa
ClassA
methodA()
ClassB
methodB1()
methodB2()
1
1
ClassB
methodB1()
methodB2()
ClassC
methodC1()
methodC2()
0..*
0..*
Polymorphism
• Polymorphism is the ability for a program to call the
same method on objects of different classes
• Whilst polymorphism isn’t explicitly part of a UML
class diagram, it’s presence can be identified in a
generalisation relationship
Polymorphism
Employee
name
employeeID
calculatePay()
SalaryEmployee
annualSalary
calculatePay()
HourlyEmployee
hourlyRate
calculatePay()
CommissionEmployee
commissionRate
totalSales
calculatePay()
The presence of multiple methods
of the same name indicates that
we are dealing with polymorphism
This is an undefined method,
because it is undefined it is known
as an abstract method that is
defined in derived classes
Package Diagrams
• Most system development projects will involve the
development of multiple class diagrams
• Organising classes into different packages that are
determined by the “business logic” can further aid
understanding of the problem domain
– It is the package diagram that is the “real domain model”
for complex systems, not the class diagram
Example Package Diagram
UI
Playlist Payment
Playback
Association Classes
• Association classes allow you to add attributes,
operations, and other features to associations
• Association classes are not always necessary and
often misused – but can be very powerful
Association Class Example
• The data in the Association Class relates specifically
to the relationship
– An alternative approach is to model Employment as a class
in it’s own right and adjust the cardinality
Employee
employeeID
calculatePay()
Company
name
1
1..*
Employment
startDate : date
endDate : date
Association Class Example
• Technically, the use of the Association Class is more
“correct” but involves more complex diagramming
Employee
employeeID
calculatePay()
Company
name
1
1
Employment
startDate : date
endDate : date
1 1..*
Conclusions
• Class Diagrams are a model of the static structure of
a system
• Most of what we’ve talked about should be revision
from P1 and P2!!

More Related Content

PPT
Uml - An Overview
PPT
08 class and sequence diagrams
DOCX
Chapterunifiedmo 3 UML Class Diagram.docx
PPTX
Unified Modeling Language and Examples .pptx
PPTX
Relationships and their representation in a class diagram.pptx
PPT
SDA ClassDiagram.ppt
PDF
Class diagram and its importance in software
PPTX
210280107093_CLASS_DIAGRAM.pptx
Uml - An Overview
08 class and sequence diagrams
Chapterunifiedmo 3 UML Class Diagram.docx
Unified Modeling Language and Examples .pptx
Relationships and their representation in a class diagram.pptx
SDA ClassDiagram.ppt
Class diagram and its importance in software
210280107093_CLASS_DIAGRAM.pptx

Similar to Lecture 06.pptxLecture 06.pptxLecture 06.pptx (20)

PPTX
introofUML.pptx
PPTX
1. introduction to uml
PPT
Week 10-classdiagrams.pptdddddddddddddddddddddddddddd
PPT
Uml class-diagram
PPT
Chapter3
PPSX
DISE - OOAD Using UML
PPT
Object and class relationships
PPTX
SMD Unit ii
PPT
PPT
Slide 5 Class Diagram
PPT
UML-class_diagram.ppt diagrams ppt download
PDF
Lecture05-Structural Modeling for students.pdf
PDF
Introduction to UML, a guide to learn.pdf
PPT
UML-class diagram for beginners to adance.ppt
PPT
cse 355 UML class diagram software engineering.ppt
PPT
UML-class_diagram.ppt
PPTX
Fundamentals of Software Engineering
PDF
Software Testing and UML Lab
PPTX
Chapter 8 ooad
PDF
OBJECT ORIENTED CONCEPTS,UML DIAGRAMS,DFD
introofUML.pptx
1. introduction to uml
Week 10-classdiagrams.pptdddddddddddddddddddddddddddd
Uml class-diagram
Chapter3
DISE - OOAD Using UML
Object and class relationships
SMD Unit ii
Slide 5 Class Diagram
UML-class_diagram.ppt diagrams ppt download
Lecture05-Structural Modeling for students.pdf
Introduction to UML, a guide to learn.pdf
UML-class diagram for beginners to adance.ppt
cse 355 UML class diagram software engineering.ppt
UML-class_diagram.ppt
Fundamentals of Software Engineering
Software Testing and UML Lab
Chapter 8 ooad
OBJECT ORIENTED CONCEPTS,UML DIAGRAMS,DFD
Ad

Recently uploaded (20)

PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Introduction to Artificial Intelligence
PPTX
L1 - Introduction to python Backend.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
System and Network Administraation Chapter 3
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
history of c programming in notes for students .pptx
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Transform Your Business with a Software ERP System
2025 Textile ERP Trends: SAP, Odoo & Oracle
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Design an Analysis of Algorithms I-SECS-1021-03
VVF-Customer-Presentation2025-Ver1.9.pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Introduction to Artificial Intelligence
L1 - Introduction to python Backend.pptx
Odoo Companies in India – Driving Business Transformation.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Softaken Excel to vCard Converter Software.pdf
System and Network Administraation Chapter 3
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PTS Company Brochure 2025 (1).pdf.......
Which alternative to Crystal Reports is best for small or large businesses.pdf
history of c programming in notes for students .pptx
CHAPTER 2 - PM Management and IT Context
Transform Your Business with a Software ERP System
Ad

Lecture 06.pptxLecture 06.pptxLecture 06.pptx

  • 2. Introduction • This session will cover: – Class Diagrams • Problem Domain • Solution Domain – Anatomy of a Class – Relationships in Class Diagrams • Generalisation (Inheritance) • Aggregation • Association – Finer Points of Class Diagrams • Polymorphism • Package Diagrams • Association Classes
  • 3. Class Diagrams • A class diagram in the UML is a static structure diagram that describes the structure of a system by showing the system's classes, their attributes, and the relationships between the classes • The class diagram is the main building block in object oriented modelling – They are being used both for general conceptual modelling of the systematics of the application, and for detailed modelling translating the models into programming code – The classes in a class diagram represent both the main objects and or interactions in the application and the objects to be programmed • As such, class diagrams are a bridge between the problem and solution domains
  • 4. Class Diagrams in the Problem Domain • The domain model is created in order to document the key concepts, and the domain-vocabulary of the system being modelled • The model identifies the relationships among all major entities within the system, and is often extended to identify their important methods and attributes • The domain model provides a structural view of the system that can be complemented by other dynamic views in Use Case models
  • 5. Class Diagrams in the Problem Domain • An important benefit of a domain model is that it describes and constrains the system scope • The domain model can be effectively used to verify and validate the understanding of the problem domain among stakeholders • It is especially helpful as a communication tool and a focusing point between technical and business teams
  • 6. Class Diagrams in the Solution Domain • The domain model is extended in the construction phase of the software development cycle since the semantics shown therein can be used in the source code • Entities can become classes, while the important methods and attributes can be carried directly to the source code – Not all entities become classes, some are purely “domain objects” – Methods and attributes are often added to as additional behaviour is required
  • 7. Anatomy of a Class • Each class is represented as a box, with three elements – The upper part holds the name of the class – The middle part contains the attributes of the class – The bottom part gives the methods or operations the class can take or undertake NamedClass firstAttribute secondAttribute firstMethod secondMethod Shape area volume getArea getVolume
  • 8. Anatomy of a Class • In the domain model, little detail is (initially) included in an individual class • As system design progresses, detail is added in terms of typecasting attributes, defining whether methods are public etc – Private methods/attributes are preceded by a – – Public methods/attributes are preceded by a + – Protected methods/attributes are preceded by a # Shape -area : int #volume : double +getArea() #getVolume()
  • 9. Relationships Between Classes • The Class Diagram is used to represent many relationships between entities (in the problem domain) and classes (in the solution domain) • The three major relationships are: – Generalisation – Aggregation (including Composition) – Association
  • 10. Generalisation (Inheritance) • Generalisation is the ability to create a base class and then derive classes from that base class • Derived classes “inherit” the attributes and methods of the base class – Exceptions are dealt with through overriding • Base classes that will never be used to create objects and just allow the creation of a derived class is an abstract class
  • 11. Generalisation (Inheritance) • Generalisation relationships are indicated using the same notation as in Use Case Diagrams • An open arrow head shows the generalisation Shape area volume getArea() getVolume() Square sideLength setSideLength() Circle circleRadius setRadius getCircumference No “set” methods, this is likely to be an abstract class The Shape class is a generalisation of Circles and Squares
  • 12. Aggregation • Aggregation is often referred to as the “whole-part” relationship – It can be considered a “has a…” relationship
  • 13. Aggregation • The aggregation relationship is indicated by a diamond icon next to the “whole” class • Arrowheads are used to indicate directionality of communication – No arrowheads indicates that communication is bi-directional Car make model drive() accelerate() Transmission changeGear() Engine increaseFuel() drive() method calls changeGear() method in transmission accelerate() method calls increaseFuel() method in engine
  • 14. Composition • Composition is a form of aggregation • In UML, composition is depicted as a filled diamond and a solid line • It always implies a multiplicity of 1 or 0..1, as no more than one object at a time can have lifetime responsibility for another object Car make model drive() accelerate() Engine increaseFuel()
  • 15. Aggregation & Composition • Aggregation differs from composition in that it does not imply ownership – In composition, when the owning object is destroyed, so are the contained objects – In aggregation, this is not necessarily true
  • 16. Generalisation & Aggregation • Both Generalisation and Aggregation can be “layered” to what ever extent is useful Shape Rectangle Square
  • 17. Generalisation & Aggregation • Both Generalisation and Aggregation can be “layered” to what ever extent is useful Order totalPrice addLineItem() LineItem numberOfItems totalPrice() Item price
  • 18. Association • The association relationship is simply a relationship that means two classes “communicate” • Often one class provides a service to another or one class starts a series of events by executing a method of another class • Associations are drawn as lines/arrows connecting classes
  • 19. Association • The line between classes tells us something about the relationship • In this example, there is a uni-directional relationship – An object of ClassA can call methods of an object from ClassB, but not vice-versa ClassA methodA() ClassB methodB1() methodB2()
  • 20. Association • In this example, there is a bi-directional relationship – An object of each class can invoke methods in objects of the other class • In UML, bi-directional relationships are not modelled as double- headed arrows but the absence of arrows ClassA methodA() ClassB methodB1() methodB2()
  • 21. Cardinality • Association and Aggregation relationships can be further refined by defining the cardinality of the relationship – One to many, many to many, mandatory etc • The following notation is used in UML 1 No more than one 0..1 Zero or one * Many 0..* Zero or many 1..* One or many
  • 22. Aggregation Example • Each order object must have at least one line item object • Each line item object must belong to one order Order totalPrice addLineItem() LineItem numberOfItems totalPrice() Item price 1 1..* 1 1..*
  • 23. Association Example • A specific object of ClassA must have a relationship with a specific object of ClassB • A ClassB object may have a relationship with any number of ClassC objects – And vice-versa ClassA methodA() ClassB methodB1() methodB2() 1 1 ClassB methodB1() methodB2() ClassC methodC1() methodC2() 0..* 0..*
  • 24. Polymorphism • Polymorphism is the ability for a program to call the same method on objects of different classes • Whilst polymorphism isn’t explicitly part of a UML class diagram, it’s presence can be identified in a generalisation relationship
  • 25. Polymorphism Employee name employeeID calculatePay() SalaryEmployee annualSalary calculatePay() HourlyEmployee hourlyRate calculatePay() CommissionEmployee commissionRate totalSales calculatePay() The presence of multiple methods of the same name indicates that we are dealing with polymorphism This is an undefined method, because it is undefined it is known as an abstract method that is defined in derived classes
  • 26. Package Diagrams • Most system development projects will involve the development of multiple class diagrams • Organising classes into different packages that are determined by the “business logic” can further aid understanding of the problem domain – It is the package diagram that is the “real domain model” for complex systems, not the class diagram
  • 28. Association Classes • Association classes allow you to add attributes, operations, and other features to associations • Association classes are not always necessary and often misused – but can be very powerful
  • 29. Association Class Example • The data in the Association Class relates specifically to the relationship – An alternative approach is to model Employment as a class in it’s own right and adjust the cardinality Employee employeeID calculatePay() Company name 1 1..* Employment startDate : date endDate : date
  • 30. Association Class Example • Technically, the use of the Association Class is more “correct” but involves more complex diagramming Employee employeeID calculatePay() Company name 1 1 Employment startDate : date endDate : date 1 1..*
  • 31. Conclusions • Class Diagrams are a model of the static structure of a system • Most of what we’ve talked about should be revision from P1 and P2!!