Professional Documents
Culture Documents
Lecture 10 - Object Oriented Modelling Within XP - CCD
Lecture 10 - Object Oriented Modelling Within XP - CCD
Dr A.Kyriakidou
Object Oriented Analysis and Design
The problem area is viewed as objects with certain characteristics (attributes),
exhibiting certain behaviour (methods) that interact/collaborate with each other
to get things done.
An attempt to put data, process and behaviour back together again all in one object.
By keeping the three elements together, it is easier to model the real problem
domain.
Provides a cleaner and well-integrated model of system behaviour
Smooths the transition between analysis, design and programming
Supports the iterative (repeated cycles) and incremental (in smaller portions
at a time) development process.
the analysis, design and development happen at repeated cycles and in
smaller portions at a time.
Dr A.Kyriakidou
What is an Object?
OO indented to make thinking about programming closer to thinking
about the real world.
• What is an object in programming we need to ask what is an object in the real
world?
All objects of a given class are identical in structure (attributes) and behaviour
but contain different data in their attributes. Dr A.Kyriakidou
What is a Class?
• A good class captures one and only one abstraction . It should have one major
theme
• E.g. represents a kind of person, place, event or thing about which the system
will need to capture and store information.
• Each object is an instance of some class, and objects cannot be instances of more
than one class
A class is a blueprint, or prototype, that defines the attributes and the methods
common to all objects of a certain kind.
Class car:
Attributes: make, colour, type, weight etc.
Behaviour: start_engine(); drive()
deposit() + deposit(real)
Behaviour withdraw() + withdraw():real
(operations/methods)
Dr A.Kyriakidou
UML Class Notation
In classes we don’t define primary and foreign keys. This goes against the primary
principles of object orientation. It’s not an ERD!
Dr A.Kyriakidou
Object/Class Principles
• Identity - an object knows who it is
• Classification - an object knows the class it belongs to
classify objects to later create similar objects as needed
• Relationships - an object knows of other objects to interact with
this helps to determine inputs and outputs of an object
• Abstract behaviour – an object performs actions/operations/functions,
it does things, it has a specific behaviour
the way data is processed within an object
300
£
300
” £
own
r
Mr.
.r B wn”
“M B ro
Bro me to
ll r.
Bi to M
S old
en
wn
d
Be
Sen
ou’ve
“Y
OOAD is based on a set of principles that serve to manage and reduce the
complexity of the world.
Dr A.Kyriakidou
Object Oriented Approach Principles
Information Hiding
• A class should hide details of how they are internally implemented as computer
code from other classes.
• Allows for the data (attributes) not to be visible to the outside world, thus
methods are the ones to allow other objects to access the data in a controlled
fashion.
Dr A.Kyriakidou
Object Oriented Approach Principles
Encapsulation:
Combining both attributes and behaviour in a class and hide the non relevant
detail at a given scale.
If you put data and process together you support abstraction as Objects can
be used as building blocks which can be put together to make the system.
Encapsulation allows for a more robust model, easier to reuse and easier to
maintain Shell
White
Yolk
• 100% Rule - The subclass must conform to 100% of the superclass's attributes,
behaviour and associations Payment
1 Sale
1
amount: Money
Generalisation Specialisation
User
name: String
address: String
Inheritable
age: int
gender: Char
Attributes
and display()
+ +
login()
Behaviour
display() display()
Student login() Academic login()
gpa: real position : String
status: Char
Super-class: User
enroll() recordGrades()
Sub-class: StudentdisplayGPA
and Academic
() recordAttendance()
Dr A.Kyriakidou
Object Oriented Approach Principles
Polymorphism
General characteristics of a class can be inherited but overridden if need be.
Allowing operations of different object classes to have the same name, whilst the
details of the actual operation carried out may be different.
• E.g. “Close method” a door can “swing shut” a window can “slide
downwards”
PRINT
25000 BLUE SKY A
20000 I R L I N E S Sales
GRAPH object
15000 Report January
10000
5000 BLUE SKY A
I R L I N E S Sales
0
Report February
North South East West
Dr A.Kyriakidou
Classes – Entity or Business Classes
• Things that have common, similar attributes, behaviours, and
common semantics (eg. People, Product)
• Occurrences or events that are part of the information domain for the problem
(eg. payroll system initiating bank transfers)
• Roles played by people who interact with the system (eg. managers, students)
• Organisational units (eg. working teams, department) that are relevant to the
system under development
• Places (eg. a manufacturing floor) that establish the context of the problem and
the overall function of the system
Dr A.Kyriakidou
Responsibility Collaborator
– one card per class
– Responsibilities: something that the - Keep new and
saved messages MessageQueue
class knows (keeps track of) or does). - Manage the class
High level responsibilities only recorded greeting
– Collaborator: another class that the
current class has to work with to To successfully keep new and saved
complete its responsibilities messages – need to send them to
– A class that has information we MessageQueue to be stored
need
– That helps perform a task
Pruning unsuitable classes
Redundant Classes Some potential classes differ only in name.
Specific Classes Model classes rather than instances e.g. supplier instead
of Andrew.
Dr A.Kyriakidou
Attributes Some nouns in the list above are likely to be modelled as
attributes rather as classes. Examples: author
3 basic categories:
Association relationships
Aggregation/composition relationships
Dr A.Kyriakidou
Associations
An association is a relationship between classes (instances of those classes)
that indicates some meaningful connection
Show how two classes are related to each other
A usage relation indicating some interaction between two classes
(they can initiate each others’ behaviour)
Criteria:
to identify check description of the problem domain (or use case
scenarios)
identify any verbs that might describe relevant relationships
between classes.
Dr A.Kyriakidou
Associations
An association is represented as a line between classes with an
association name
has-a
Association from Class A Class B
A to B means
that A uses B
directly (by calling its methods for example)
has-a
This traversal is Faculty Department
belongs to
purely abstract;
it is not a statement
about connections between software
entities
Dr A.Kyriakidou
Associations - Multiplicity
The ends of an association may contain a multiplicity expression indicating the
numerical relationship between instances of the classes. Denotes the minimum ..
maximum number of instances a class association can have.
Order * * Products
Dr A.Kyriakidou
associated classes that cannot be placed in either of the classes
˃ the relationship then becomes one-to-many and many-to-one
Order
1 * OrderLine * 1 Products
Dr A.Kyriakidou
Aggregation
Introduces no new rules - it just adds vocabulary to notation provides
clarity for design and implementation
˃ Aggregations are special associations that represent ‘whole-part’
relation. The ‘whole’ side is often called the assembly or the aggregate the
‘part’ side is-part-of the ‘whole’
Aggregation in UML means ‘has-a’ or ‘is-part-of ’
Between 1 and 6 modules are part of 1 or more program
Dr A.Kyriakidou
1..6 1..*
Module Program
Study Pack
1 1
1..* 1..*
Lecture Notes Assignments
ClassA ClassB
Dr A.Kyriakidou
˃ Class A (composite class - whole) is responsible for creating and
destroying Class B (the composed class’s object - Part) create/add () and
delete() methods included in the composite class
1 *
Building Room
Dr A.Kyriakidou
A relationship between
an object and its class Is a kind of, is one of
Being verb
(defines type of object) either
Inheritance
Aggregation/
Has-a, consists of,
Having verb Association/
includes
Composition
Modal verb Constraint Must be
Helps identify an
Adjective a yellow ball (i.e. color)
attribute
Pioneered by Russell Abbott (1983), popularized by Grady Booch
Online Book store example
Order Basket
1 0..1 creationDate: Date
creationDate: Date
status: String has qty: int
addOrderLine() totalQty: int
delOrderLine() totalPrice: Real addBasket()
delBasket ()
tackOrder()
editBasket ()
checkStatus()
checkout()
Dr A.Kyriakidou
calculateGrandTotal()
delOrder()
addOrder()
Book Book editOrder() CreditCard
title: String display()
title: StringOrderLine cardHolderName: String
author: String author: String * 1 1 expieryDate: Date
isbn: String isbn: creationDate:
String Date
genre : String cSC: int
genrestatus: String
: String cccNumber: int
qty: int 1 qty:
* intquantity: int * *
addBook()
price: Real
hasaddBook() hashas Is paid 1 validate()
addOrderLine() display()
delBook () delBook ()
delOrderLine() addCCard()
updateInventory() updateInventory()
calculateSubTotal() delCCard()
checkAvailability() checkAvailability()
getPrice() editCCard()
browseBook() browseBook()
editQty()
Dr A.Kyriakidou
Case study Example: Travel Company
A travel bus company known for their day tours in central London owns a
number of buses.
The smallest bus has 20 seats.
Each bus carries out a number of tours.
When a new tour is scheduled, the company assigns a bus to it and issues
one ticket for each seat on the bus.
Customers buy tickets for a tour. In order to travel, each customer must
have a valid ticket.
Some popular tours are totally booked, but on some less popular ones a
bus may travel with some empty seats.
Dr A.Kyriakidou
Travel Company Sample Solution
Customer
name: String
address: String
password: String
user_name: String
addCustomer()
delCustomer()
Tour
Solution ?
editCustomer()
Dr A.Kyriakidou
name: String login()
logout()
Bus description: String displayProfile()
1 *
coachAvailability: Bool 1 Seat
coachCaoacity : Int add_Trip()
delete_Tript() * seatNumber: int
check_Avail() Ticket
add_Coach()
assign_Coach
get_price() 1 1
create_ticket() name: String applySeatPref()
checkSeatAvail()
1 1 get_ticket()
* set_ticket() *
print_ticket()
Dr A.Kyriakidou
Wrap Up – Building Conceptual Class Diagrams
Step 1: Find the potential classes/objects.
review each use-case and its description to find “nouns” that correspond
to business entities
Step 3: Identify possible attributes and methods for each class. Use language helpers
Dr A.Kyriakidou