Documente Academic
Documente Profesional
Documente Cultură
Object-Oriented
Approach
Learning Outcome
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)
Objects
Objects have state, behaviour and
identity.
Booch (1994)
Examples of Objects
Object
Identity
Behaviour State
A person.
Hussain Pervez.
Studying, resting,
qualified.
A shirt.
My favourite button
white denim shirt.
Pressed, dirty,
worn.
A sale.
Sale no #0015,
18/05/11.
Invoiced,
cancelled.
A bottle of
ketchup.
This bottle of
ketchup.
Spill in transit.
Unsold, opened,
empty.
<Object Name>
We use a rectangle to
represent an object and
place the underlined
name of the object
inside the rectangle.
Example:
SV198
Example:
Account
We use a rectangle to
represent a class with
its name appearing
inside the rectangle.
Motorcycle
Example:
SV198 : BankAccount
Attribute
Minus sign
indicates
these are
private
(hidden)
Operation
A behavior of an object
Method
implements
the behavior
Sending a Message
Message deposit with
the argument 250.00 is
sent to a BankAccount
object SV198.
deposit 250.00
SV198 : BankAccount
getCurrentBalance()
SV198 : BankAccount
current balance
MobileRobot
getMaximumSpeed()
maximum speed
Generalization and
Specialization
Specialization Hierarchy
More general
(superclasses)
Person
Employee
monthly paid
Customer
weekly paid
Driver
Cleaner
Supplier
hourly paid
Sales
assistant
More specialized
(subclasses)
Generalization and
Specialization
More general bits of description are abstracted
out from specialized classes:
SystemsAnalyst
name
employee-no
startDate
monthlySalary
grade
Driver
name
employee-no
startDate
standardHourlyRate
overtimeRate
licenceType
Specialized (subclasses)
General (superclass)
Employee
name
employee-no
startDate
SystemsAnalyst
monthlySalary
grade
Driver
standardHourlyRate
overtimeRate
licenceType
Inheritance
Employee
name
employee-no
startDate
SystemsAnalyst
monthlySalary
grade
Driver
standardHourlyRate
overtimeRate
licenceType
Instances of each
subclass include the
characteristics of the
superclass (but not
usually shown like this on
diagrams)
:Driver
name
employee-no
startDate
standardHourlyRate
overtimeRate
licenceType
:SystemsAnalyst
name
employee-no
startDate
monthlySalary
grade
Aggregation and
Composition
Aggregation and
Composition
27
Encapsulation
The characteristic of
object-orientation in
which data and behavior
are bundled into a class
and hidden from the
outside world
Plus sign
indicates
these are
public
(accessible)
Operation signature is an
interface through which an
operation can be called.
Data used by an
operation is located in
the object too
30
Representation of data
is hidden inside object
31
Polymorphism
Polymorphism allows one message to be
sent to objects of different classes
Sending object need not know what kind
of object will receive the message
Each receiving object knows how to
respond appropriately
For example, a resize operation in a
graphics package
32
Polymorphism
An example of Polymorphism
Component
Interface
36
Interfaces are
represented as
small rectangles
Package
An example of a Package
Account
Object Persistence
Objects lifetime
require technologies (e.g., data
storage) to provide support for objects
having a longer lifeline longer than the
duration of the process for which they
were created
To be able to retain and quickly
access the information defined by an
object
40
OO Justification
Encapsulation of data and functions into
object classes, no function without
corresponding data some basic
consistency constraints are insured
Information hiding is the principle of
concealing the internal data and
procedures of an object
Interface to reveal as little as possible
about the objects inner working
41
OO Justification
Inheritance allows:
objects to be built from other objects
reusability
objects to change and evolve over
time changing base classes
changes the properties and attributes
of a class
42
OO Justification
Polymorphism
allows to write generic, reusable code
more easily specify general
instructions and delegate the
implementation details to the objects
involved
easier maintenance
43
OO Justification
The OO system architecture consists
of a set of interacting objects
Objects communicate and interact to
fulfill the required system functionality
OO system eliminates duplicated
effort by allowing classes to share and
reuse
44
Advantages of O-O
Summary
In this lecture you have learned about:
The fundamental concepts of O-O
Object, class, instance
Generalization and specialization
Message-passing and polymorphism
References
Bennett, McRobb and Farmer (2010)
George, Batra, Valacich and Hoffer
(2007)