Professional Documents
Culture Documents
OOSAD UML - Lec02 1
OOSAD UML - Lec02 1
OOSAD UML - Lec02 1
& Design
Object
8/26/03
Course Covers 3
Issues
Quality Software
Less effort (easy
development
process)
Less cost and time
Quality Software ?
Reliable
- Reusable
Robust
- Maintainable
Efficient
- Userfriendly, etc.
8/26/03
Analysis
OO
Design
OO
Programming
OO
Database
8/26/03
Evolution - to OO
Approach
Early machine- single programmermachine code & assembler
Next level machines- High level
programming
Moderate machines- program groups
GOTO - structured programming
Efficient machines- Structured Design
and Analysis methods
6
Evolution- to
OO
Very efficient machines
demands very complex systems
efficient methodologies - O-Oriented, ?
case tools
programming environments
reusable components, etc.
Abstraction
Focus only on essential issues
Ignores unnecessary detail Tiger
E.gs
All are
Human Bones Nerves Heart
Requirements-driven development
Component-based development
Architecture-centrism
Visual modelling techniques
USDP
Phases
Inception
Elaboration
Construction
Transition
Work Flows
Requirement Capture
Analysis
Design
Implementation
Testing
10
Project
Phases
Elaboration
8
Iterations
within each
phase
Requirements
The balance
of effort
spent in
each
workflow
varies from
phase to
phase
Analysis
Design
Implementation
Test
Workflows
Transition
Construction
Size of
square
relative to
time spent
on
workflowh
11
accNo
module
viewBalance
balance
Quality software
Easy
development
process
13
myAccount
14
Seamless Transition
Structured Vs OO approach
Structured
Account
amount
message
aNo
withdraw
amount
message
withdrawal
balance
Account
ER
OO approach
Objects
Structure Chart
MyAccount::
aNo= 101
balance=500
withdraw(X)
:MyAccount
balance( )
withdraw( )
--16
17
avoided
19
20
Model
A model follows standards
A model provides a complete view of a
system from a particular perspective.
A model may consist of a single
diagram or consist of many related
diagrams and supporting data and
documentation.
Eg. Usecase model in UML consist of Usecase diagram and use-case descriptions
UML- an introduction
More on UML
23
Diagrams in UML
Activity
diagram
Plan Chapter
Produce
First Draft
icons
two-dimensional symbols
paths
Strings
Revise Draft
[not satisfied]
[satisfied]
Add Exercises
Add References
to Bibliography
Author
Activity
Diagram
An Example:
Activity
diagram of the
tasks involved
in producing a
book.
Using Swimlanes
Reviewer
Typesetter
Printer
Write Chapter
Review Chapter
Revise Chapter
[book not
complete]
[book complete]
Typeset Book
Correct Proofs
Reset Book
Print Book
25
logical view
process view
implementation view
deployment view
And
use case view
Structural Modelling
Static View ( Class Diagram)
Behavioural Modelling
Functional View (Use-case , Activity
Diagrams)
Dynamic View (Interaction Diagrams sequence and collaboration)
Temporal View (State Chart)
Architectural Modelling
Implementation view (Component Diagram)
27
Configuration view ( Deployment Diagram)
Requirements Model
complete view of requirements
may include other models, such as a Use Case
Model - includes textual description as well as sets of
diagrams
Behavioural Model
shows how the system responds to events in
the outside world and the passage of time
an initial model may just use Collaboration
Diagrams and a later model will include
Sequence Diagrams and State charts
28
Iteration 1
Obvious use cases.
Simple use case descriptions.
Accountant
Change the
rate for a
staff grade
Change the
rate for a
staff grade
Change the
grade for a
staff member
Accountant
Change the
grade for a
staff member
Calculate staff
bonuses
Calculate staff
bonuses
Staff Management
Iteration 2
Additional use cases.
Simple use case descriptions.
Prototypes.
Iteration 3
Structured use cases.
Structured use case descriptions.
Prototypes.
Campaign Selection
Accountant
Change the
rate for a
staff grade
Change the
grade for a
staff member
Holborn Motors
Lynch Properties
Holborn
Motors
Yellow
Partridge
Yellow
Partridge
LynchZeta
Properties
Systems
Holborn
Motors
Yellow
Partridge
Yellow
Partridge
Spring Jewellery Campaign 1997
Properties
Systems
Campaign:LynchZeta
Spring Jewellery Campaign 2001
Yellow Partridge
Spring
Jewellery
Campaign
1997 2002
Spring
Jewellery
Campaign
Zeta Systems
Campaign:
Spring
Jewellery
Campaign
2001
Summer
Collection
1998
Spring
Spring Jewellery
Jewellery Campaign
Campaign 2002
Campaign:
2002
Summer Collection 1998
OK
Quit
Client:
Campaign Selection
Client:
Change the
grade for a
staff member
Change the
grade for a
staff member
Accountant
Campaign Selection
Change the
rate for a
staff grade
Change the
rate for a
staff grade
Client:
Calculate staff
bonuses
Calculate staff
bonuses
OK
Calculate staff
bonuses
OK
Quit
Quit
Campaign Management
Assign staff
to work on
a campaign
include
Campaign Management
Assign staff
to work on
a campaign
Assign staff
to work on
a campaign
Campaign
Manager
Campaign Selection
Find campaigninclude
Campaign Selection
include
Add a new
advert to
include
a campaign
Check campaign
include
Add a new
advert to
a campaign
extend
Print campaign
summary
Print campaign
summary
extend
extend
Accountant
extend
Accountant
Print campaign
summary
Client:
extend
Check campaign
include
budget
extend
Check campaign
budget
Print campaign
invoice
Print campaign
invoice
Holborn Motors
Lynch Properties
Holborn
Motors
Yellow
Partridge
Yellow
Partridge
LynchZeta
Properties
Systems
Holborn
Motors
Yellow
Partridge
Yellow
Partridge
Spring Jewellery Campaign 1997
Properties
Systems
Campaign:LynchZeta
Spring Jewellery Campaign 2001
Yellow Partridge
Spring
Jewellery
Campaign
1997 2002
Spring
Jewellery
Campaign
Zeta Systems
Campaign:
Spring
Jewellery
Campaign
2001
Summer
Collection
1998
Spring
Spring Jewellery
Jewellery Campaign
Campaign 2002
Campaign:
2002
Summer Collection 1998
OK
Quit
Client:
Campaign Selection
include
budget
Find campaign
Campaign
Manager
Accountant
Find campaign
include
Add a new
adv ert to
include
a campaign
Campaign Management
Campaign
Manager
Print campaign
invoice
Client:
OK
OK
Quit
Quit
29
OBJECTS
30
31
Polymorphism
32
Objects
An object is:
an abstraction of something in a
problem domain, reflecting the
capabilities of the system to
keep information about it,
interact with it,
or both.
Coad and Yourdon (1990)
33
Objects
Objects, an abstraction of a real-world
thing, that have state, behaviour and
identity.
Booch (1994)
34
-- abstraction of something in a
domain--
Public
CAR- in game SW
Vs
CAR - in Insurance SW
draw( ), changeSpeed( )
getValue( ), getOwner( )
In SWD process,
Only
necessary
attributes,
behaviors
and
relationships of objects related to the problem
domain are abstracted
35
Example
Car
My car is a car.
It is not a truck
is an object
Identity my car
State (current )
Behavior
Start, Off, ChangeSpeed(?),
getPetrolLeft( ?)
Identity
37
State
COPY
?
OnShelf
OnHold
OnBind
OnReserve
38
ChangeSpeed(100)
Behaviour
gear=neutral
Complete this !
COPY
OFF
onShelf
onLoan
Class
All objects are instances of some class
Class: a description of a set of
objects with similar
attributes,
operations or methods
relationships and semantics.
An object is:
an instance that
originates from a class, it is structured
and behaves according to its class.
OMG (2001)
40
OMG (2001)
41
Class and
Objects
42
Account
Class
variable
aNo
balance
dayLimit = 200
balance(?)
withdraw(X)
SamAcc::
aNo=101
balance=500
balance( )
withdraw( )
---
Name of
Class
Data
Declaration
Methods
Definition
instances
SamAcc::Account
aNo = 101
balance = 500
Name of
Object
MicAcc::Account
Data Values
aNo = 105
balance = 600
Name of
Object
Data Values
43
VCR
Advantages
Easy to use
More Reliable
Reduce Coupling
pause
44
Encapsulation
-3 advantages ? )
easy to use
more reliable
less coupling
Name of Class
Data
(usually hidden)
Methods
(usually interface)
balance(?)
withdraw(X)
My Account::
aNo=101
balance=300
45
Message-passing
Encapsulation protects ad-hoc object
access
For each class legal interface is given in
order to get its services (public methods)
Interloan
Messageuser
library
passing
Client object request a service from a
request
methods
service
MyAccount::
withdraw( )
method
deposit( )
message
aNo
balance
47
Message-passing and
Encapsulation
Layers of an onion
model of an object:
An outer layer of
operation signatures
gives access to middle
layer of operations
which can access
inner core of data
An objects data
is hidden
(encapsulated).
48
amount
withdraw
message
amount
message
withdrawal
balance
Account
ER
Which is more
reusable?
Account
aNo
balance
balance( )
withdraw( )
---
Structure Chart
Class &Object
withdraw(X)
MyAccount::
aNo=101
balance=300
49
Generalization and
Specialization
Classification is hierarchic (disjoint and
transitive) in nature
It is an outcome of natural abstraction
For example,
a person may be an employee, a
customer, or a supplier
Specialization
Hierarchy
Abstraction
Person
Employee
monthly
paid
More general
(superclasses)
Customer
weekly
paid
Driver
Cleaner
Supplier
hourly
paid
Sales
assistant
More specialized
(subclasses)
51
Person
Name
Date of birth
Gender
Title
age ( )
Specialized (subclass)
HourlyPaidDriver
StartDate
StandardRate
OvertimeRate
LicenceType
52
Student is a person.
Whatever true for a person is true for a student.
Student is a special type of person.
extramural internal
is
Inheritance - an G&S
implementation
The whole description of a super or base
Inheritance - an example
Savings class now
have, 4 attributes and
3 methods
MySavings.balance( )
Account
aNo
balance
balance( )
withdraw( )
class variables
withdraw( ) will
be overridden.
Why we need
withdraw( ) in
Account class?
Savings
Current
dayLmt
daySofar
withdraw( )
reset( )
odLmt
withdraw( )
Design View
Increases reusability; properties of the parent class
are passed to subclasses without redefining them.
Global View
Provides extendibility; a well-defined object, even its
source code is not available, may be extended to
suit a particular problem domain. (eg. In Java?)
56
class variable
Current
odLmt
withdraw( )
reset( )
57
More on
InheritanceOverlapping?
Student
Disjoint?
Internal
Member
Staff
Student
Local
Discriminator
Student
Complete?
Student
Asian
type
mode
International
Local
Local
PGrads
UGrads
LocalPGrads
58
Multiple
AInheritance
class may be member
Staff
Support Academic
PGrad
UGrad
PGdAcad
Poly-morph- ==>Many-form-ism
ism
Poly means many and morph means
forms. One message may be sent to
objects of different classes of a family
Sending object need not to know what
kind of object will receive the message
Each receiving object knows how to
respond appropriately
Jesu
s
Buddah
Pray!
A---
Siva
60
Polymorphism - Examples
resize( x)
<<entity>>
Campaign
Resize Operations
title
campaignStartDate
campaignFinishDate
getCampaignAdverts()
addNewAdvert()
<<entity>>
Campaign
resize( x)
title
campaignStartDate
campaignFinishDate
getCampaignAdverts()
addNewAdvert()
Withdraw()
::ATM interface
Account
Withdraw()
OR
Withdraw()
::Savings
::Cheque
Do you know which account will be used in ATM machine next time ?
Why we need an abstract method withdraw() in Account class ?
61
Overloadin
g
He is noodlesSpoonEating.
He is noodlesStickEating.
He is riceSpoonEating.
He is riceStickEating.
My car is eating petrol
Is it possible
in pascal?
62
Overrriding
Inherited polymorphism
Which is
Polymorphism?
Ad-hoc Same class, different tasks
:Class1.method1(paralist1)
overload
:Class1.method1(paralist2)
Inherited
Run-time
method1(paralist1);
method1(paralist2);
method2(paralist);
:Class1.method1(paralist2)
inherit
:Class2.method1(paralist2)
Class1
Class2
method1(paralist1);
:Class1.method1(paralist1)
Override (which method? - not
:Class2.method1(paralist1)known until run time)
requestMoney
user
withdraw( )
::ATM interface
withdraw()
::Savings
Account
withdraw()
::Cheque
65
accNo
balance
balance( )
withdraw( )
Savings
withdraw( )
Cheque
ODLimit
withdraw( )
}
66
Account
accNo
balance
balance( )
withdraw( )
Savings
Cheque
ODLimit
withdraw( )
}
67
Account
accNo
balance
balance( )
withdraw( )
Cheque
ODLimit
withdraw( )
68
Account
accNo
balance
balance( )
withdraw( )
Cheque
ODLimit
withdraw( )
69
Account
accNo
balance
balance( )
withdraw( )
Cheque
ODLimit
withdraw( )
70
Advantages of
Polymorphism
Conceptually,
it provides
a mechanism to
represent a concept of an act as we percieve it
usually
without giving different names for similar concepts.
Inherent polymorphism supports reusability of
a method.
a base class method may be used in its sub classes
without redifining it.
Run-time polymorphism supports reusability of
a whole object.
can extend an object to suit our requirement.
The withdraw() method could be redefined in
ChildSavings. Therefore, the entire Savings class
71
may be reused.
72
Relationships(sta
lend
UML
Tom
giveDetail( )
tic)
Objects do not exist in isolation. They need to
Association
Aggregation (and Composition)
Generalization-Specialization
Dependency relationship will be discussed later.
73
Association
Link
Farmers
worksF
Tom
or
employer
employee
LINK - is a semantic connection between two objects that facilitates message passing.
Association
interactions
Link.
is an instance of
worksF
0..
0..*
person
or
1*
employer
employee
74
Multiplicit
y
worksF
0..
0..*
person
compan
or
1
employer
employee
y
Employee *
person
1
manager
Other
Constraints
Ordered
Holds must be in some
order
Subset
Manager must be an
employee
XOR
Prevents artificial
subclasses
book
compan
y
Person
Organiz
a
placeO 0..*
n
{ordere
d}
employee
*
{subset
}
manager*
hold
person
account
* perOwne
*
r
{exclusive
account Account
or}
1 orgOwne
*
r
76
Tertiary
Relations
Lecturer
Student
Course
Schedule
room
time
L1 take C1 for S1 in R1
L1 take C1 for S2 in R2
OR
Lecturer
Student
<<ternary>>
Course
Schedule
Another example?
room
time
77
account
1..*
UsedFor
Attributed
Association
Only used to hold
attributes of a
relationship
student
0..*
Association
class
dateInclude
d
0..*
card
1..*
course
No Name
grade
78
Aggregatio
n
Staff
*
Dependants
*
*
*
Degree
Compositio
n This may be recursive.
Invoice
Drawing
Line
Circle
Invoic-Lines
Account
nextAno
- aNo
# balance
-
+ balance( )
+ withdraw( )
Package ??
Visibility affects the accessibility
of a class member
outside its
boundary
81
Account
Visibility
- aNo
# balance
MySAcc:Savings
balance = balance
amount
nextSAno =5021
aNo = 123
balance = 540
dayLimit = 100
soFar = 25
withdraw( )
---
+ balance( )
+ withdraw( )
MyCAcc:Current
nextCno = 601
aNo = 321
balance = 5640
ODlimit = 1000
withdraw( )
---
setBalance(balance( )-amount)
82
Binding
Static binding
Determined at compile time
Dynamic binding Determined later at run time
X.withdraw( ), depends on X
X is known only at run-time
Swithdraw()
RAM
Cwithdraw()
83
Persistenc
e Objects have life-time. They explicitly
created and exist for a period.
Some objects are created during an
execution and destroyed before finish
(e.g. UI objects)
Some objects need to exist beyond
application boundaries ( in a file or DB).
This object must be retrieved in another
session in same state as it was saved.
85