Professional Documents
Culture Documents
Object Oriented Analysis & Design (OOAD)
Object Oriented Analysis & Design (OOAD)
Design (OOAD)
OOAD
Objects
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.
Objects are entities in a software system
which represent instances of real-world and
system entities
3
Objects
Object
Identity
Behaviors
State
An employee
Mr. John
Join(),
Retire()
Joined,
Retired.
A book
AddExemplar,
Rent,
available,
reserved
A sale
Sale no 0015,
15/12/98
SendInvoiced(),
Cancel().
Invoiced,
cancelled.
Object Class
Class is a description of a set of objects that
share the same attributes, operations,
methods, relationship and semantics.
Object classes are templates for objects.
They may be used to create objects.
An object represents a particular instance of
a class.
5
Term of objects
Attribute: data items that define object.
Operation: function in a class that combine
to form behavior of class.
Methods: the actual implementation of
procedure (the body of code that is executed
in response to a request from other objects
in the system).
6
Object
Employee
name: string
address: string
dateOfBirth: Date
employeeNo: integer
socialSecurityNo: string
department: Dept
ma nager: Employee
salary: integer
status: {current, left, retired}
taxCode: integer
. ..
join ()
leave ()
retire ()
changeDetails ()
Employee16
name: John
address: M Street No.23
dateOfBirth: 02/10/65
employeeNo: 324
socialecurityNo:E342545
department: Sale
manager: Employee1
salary: 2340
stauts:current
taxCode: 3432
.
Eployee16.join(02/05/1997)
Eployee16.retire(03/08/2005)
Eployee16.changeDetail(X
7
Street No. 12)
Encapsulation
private attributes and methods are encapsulated within the
class, they cannot be seen by clients of the class
public methods define the interface that the class provides
to its clients
Customer
private attributes
public methods
- numCustomers = 0
- MIN_BUDGET = 200
- name: String
- address: String
- budget: int
+ printNumCustomer( ): void
+ placeOrder( ): void
Customer class
Object communication
Objects communicate with each other by sending
messages
a message is a method call from a message-sending
object to a message-receiving object
a message consists of
an object reference which indicates the message receiver
a method name (corresponding to a method of the receiver),
and
parameters (corresponding to the arguments of the calling
method)
10
Message Passing
message
name = Alex
address =
1 Robinson Rd
budget = 2000
placeOrder( ): void
alex
takeOrder(sofa, name,
address, 120799)
199
return value
message
name = Lawrence
employeeNo =15
commission = 200
takeOrder( ): int
lawrence
method name
parameters
11
Message Passing
Customer
SalesPerson
- numCustomers = 0
- MIN_BUDGET = 200
- name: String
- address: String
- budget: int
+ printNumCustomer( ): void
+ placeOrder( ): void
alex
client
+ takeOrder( ): void
takeOrder
lawrence
server
12
Inheritance
Object classes may inherit attributes and
services from other object classes.
Inheritance represents the generalization of
a class.
13
A generalisation hierarchy
Employee
Ma nager
Programmer
budgetsControlled
dateAppointed
project
progLanguage
Project
Ma nag er
projects
De pt.
Ma nager
dept
Strategic
Ma nag er
responsibilities
14
Library Item
Library class
hierarchy
Catalogue Number
Acquisition date
Cost
Type
Status
Number of copies
Acquire ()
Catalogue ()
Dispose ()
Issue ()
Return ()
Published item
Title
Publisher
Book
Author
Edition
Publication date
ISBN
Magazine
Year
Issue
Recorded item
Title
Medium
Film
Director
Date of release
Distrib
Computer
program
Version
Platform
15
Reader
Borrower
Items on loan
Max. loans
Affiliation
Staff
Department
Department phone
Student
Major subject
Home address
16
Multiple inheritance
Rather than inheriting the attributes and services
from a single parent class, a system which supports
multiple inheritance allows object classes to inherit
from several super-classes
Can lead to semantic conflicts where
attributes/services with the same name in different
super-classes have different semantics
Makes class hierarchy reorganisation more
complex
17
Multiple inheritance
Book
Voice recording
Author
Edition
Publication date
ISBN
Speaker
Duration
Recording date
Talking book
# Tapes
18
Advantages of inheritance
It is an abstraction mechanism which may
be used to classify entities
It is a reuse mechanism at both the design
and the programming level
The inheritance graph is a source of
organisational knowledge about domains
and systems
19
21
Objects Association
Modeling an association between two classes means
that there is some sort of relationship between objects
of each class that may be connected.
Student
studies
0..*
1..*
Course
22
Object aggregation
Aggregation model shows how classes
which are collections are composed of other
classes
Similar to the part-of relationship in
semantic data models
23
Object aggregation
Study pack
Course title
Number
Year
Instructor
1
1 ..*
1 ..*
Assignment
1 ..*
1 ..*
#Problems
Description
OHP slides
Slides
Credits
Exercises
1
1 ..*
Lectur e
notes
Text
0 ..*
Videotape
Tape ids.
Solutions
Text
Diagrams
24
Polymorphism
the ability of different objects to perform the appropriate
method in response to the same message is known as
polymorphism.
the selection of the appropriate method depends on the class
used to create the object
Shape
radius
calculateArea( )
Circle
name
getName( )
calculateArea( )
Square
side
calculateArea( )
26
Example Polymorphism
class Shape {
private String name;
public Shape(String aName) { name=aName; }
public String getName( ) { return name; }
public float calculateArea( ) { return 0.0f; }
a generic action
inheritance
overriding
27
28
Polymorphism Example
public class ShapeDemoClient {
public static void main(String argv[ ]) {
Shape
Shape
Shape
Shape
Shape
rule of subtype
29
Identifying Object
Objects can be:
External Entity (e.g., other systems, devices, people)
that produce or consume information to be used by
system
Things (e.g., reports, displays, letters, signals) that are
part of information domain for the problem
Places (e.g., books room) that establish the context of
the problem and the overall function of the system.
Organizational units (e.g., division, group, team,
department) that are relevant to an application,
Transaction (e.g., loan, take course, buy, order).
32
33
Candidate objects:
Just a Line
site
car park
number
card reader
system
sign
management
employee
card
member of staff
entrance
signal
visitor
security
people
name
access
driver
exit
reception
building
company
department
barrier
car
space
34
35
Rejection criteria
management,company,
building, site, visitor and
reception
security, people
vague
system
too general
name, department,
attribute
access
association
driver
role
36
Rest Objects
Car park
Employee
card reader
space
Staff Card
Entrance
barrier
sensor
Visitors card
exit
Full sign
car
37
Full sign
on:boolean
switch on()
switch off()
Card Reader
valid card nos.
read card()
card OK()
38
Data Dictionary
Barrier: type + up
type = [Entrance|Exit]
up = [true|false]
raise: if the barrier is not already raised, this operation takes as
argument an object of the barrier class and returns an object of the
same class, with the up attribute set to true. If the barrier is already
up, the operation returns the error message barrier is already raised
lower: if the barrier is not already lower, this operation takes as
argument an object of the barrier class and returns an object of the
same class, with the up attribute set to false. If the barrier is already
down, the operation returns the error message barrier already
lowered.
39
Objects Relationship
Car Park
2 ..*
Barrier
Car Park
1 ..*
2 ..*
Card Reader
Sensor
1 .. *
1
Valid cards
1 .. *
Card
Visitors Card
Staff Card
40
:CarPark
:Sensor
:CardReader
:Valid card
:Barrier
:Full Sign
Car present
Check space left
Yes
Card number
Card number
Card returned
Card OK
Raise
Car not present
lower
Decrement Space
Check space left
Yes
42
44
45
Structured Model
46
Comparison
OO:
Systems decomposed into
collections of data objects;
function + data in one place =>
System components more
independent => more resilient
to requirements and
maintenance changes.
Inheritance and polymorphism
are possible => reuse,
extension, and tailoring of
software/designs is possible.
Closely mirrors how humans
decompose and solve
complex.
Structured:
Systems decomposed into
functions; functions and data
modelled separately =>
System components are more
dependent on each other =>
requirements and
maintenance changes more
difficult
Inheritance and polymorphism
not possible => limited reuse
possible.
System components do not
map closely to real-world
entities => difficult to manage
47
complexity.
Comparison
OO:
Process allows for iterative and
incremental development =>
Integration of programs is
series of incremental
prototypes.
Users and developers get
important feedback
throughout development.
Testing resources distributed
more evenly.
If time is short, coding and
testing can begin before the
design is finished.
Structured:
Process less flexible and largely
linear =>
Integration of programs is big
bang effect.
Users or developers provided
with little or no feedback; see
system only when it has been
completed.
Testing resources are
concentrated in the
implementation stage only.
Coding and testing cannot
begin until all previous stages
are complete.
48