Professional Documents
Culture Documents
IT60105
Lecture 5
• Classifications
– Inheritance
– Delegation
• Polymorphism
– Dynamic Binding
• State
The group of values of all attributes at a given point
of time
e.g. Car Car
•modelNo
•color
•engineNo
Note:
•controlPanel
Some state attributes are constant Where
•speedoMeter
as some are dynamically change
•distanceTravelled
e.g .distanceTravelled, fuelStatus
•fuelStatus
• Behavior
The group of all abilities of an object and describes the action and reaction
among the objects
C a r
S t a t e
D r iv e r
s t a r t ( ) E n g i n e
S t a t e a c c e l e r a t o r ( )
r e t a r d a t e ( ) S t a t e
s t a r t E ( )n g i n e s t o p ( )
s t o p E ( )n g i n e i g n it e ( )
b r e a k ( ) t u r b o ( C) y c l e
f a s t ( ) c y c l(e ) O n
s lo w ( ) Note: Behavior is the means of c y c l(e ) O f f
interface between two or more objects.
• Identity
The characterization of its existence. The identity makes it possible to
distinguish an object in an unambiguous way and independently form its
group
e.g.
Car – carNo
Borrower – borrowerNo
Person – empId / voterId / rollNo
m e s s a g e A
O b j e c t A O b j e c t B
m e s s a g e B
• Type of objects
– Active objects
– Passive objects
– Transient/ephemeral objects
– Persistent objects
M o r e A b s t r a c t
O b j e c t s
H i g h
A b s t r a c t D a t a T y p e s
Simplification
F u n c t i o n s
M n e m o n i c s
L o w
B i n a r y C o d e
M o r e d i f f i c u l t
• Challenges
– Real world objects are too complicated to manipulate
• Solution
– To reduce inherent complexity object oriented paradigm
have been formulated
• Encapsulation
• Relation
• Classification
• Polymorphism
•Encapsulations
•Combined data and methods to manipulate data into one
entity
•Class is the concept of encapsulation
•A varieties of objects are grouped together such as book,
car, ..etc
•A set of similar objects grouped together with some
distinguishing structure (at a high level of abstraction)
•Class is a process of abstraction
10 August, 2006 Information System Design IT60105, Autumn 2006
O-O Paradigms: Encapsulation
• Graphical representation of a class
C l a s s n a m e
A t t r i b u t e s
o p e r a t io n s
Car
•modelNo
Example: Car •color
•engineNo
•controlPanel
start()
accelerate()
retardate()
Stop()
10 August, 2006 Information System Design IT60105, Autumn 2006
O-O Paradigms: Encapsulation
Exercise: Give possible class structure to the following
• Set
• Complex number
• Rational number
• TV set
• Customer (of a Bank)
• Account (of a customer in a Bank)
• Stack/ Queue/Tree/Graph/Vector
• Bi-directional
– Data may flow across the association (This is unlike data flow in DFD)
• Semantic connection
– An association between classes means that there is a link between
objects in the associated class
P e r s o n O f f e r e d b cy o u r s e
A n A s s o c ia t i o n
C l a s s A C l a s s B
E x a m p l e :
E n r o l ls
U n iv e r s it y S t u d e n t
C h il d
*
1
P e r s o n
F a t h e r
B a n k
1 . . *
C u s t o 1m . . e * 1r . . * A c c o u n t
E n r o ll s
U n iv e r s i t y S t u d e n t
S t u d ie s i n
W o r k s in
P e r s o n C o m a p n y
E m p l o y e e E m p lo y e r
faculty
E m p lo y e e E m p lo y e r
Symbol Meaning
1 One and only one
0..1 Zero or one
M..N From M to N (natural integers)
* From zero to any positive integers
0..* From zero to any positive integers
1..* From one to any positive integers
1 saving *
1..* recurring *
Customer Account
2..5 current *
Example
Engine is a part of Car
Example
University has a number of department
1 h a s a
U n iv e r s i t y * D e p a r t m e n t
1 W h o l e o f
R e c t a n g le * P o in t
1
M a t r i x * N u m b e r
1
C o m p l e x N u m 2 b e I nr t e g e r
E x a m p l e o f M a n y t o M a n y :
p a r e n t
P e r s o n
0 . . 2
c h i *l d
1 follows *
Class Course
1
Rectangle * Point
University * Department
1 contains * Student
Class
1 *
Set Element
If the part moves, can one deduce that the whole moves with it?
Is the MD
People Company
1 1
Car Engine
Example:
C y lin d e r
C a r E n g in e
T u r b u r a t o r
A g g r e g a t i o n C o m p o s i t i o n
• Generalization and specialization are the two point of views that are based
on class hierarchy
More Generalized
class
Specialization
Generalization
Super class
More Specialized
Sub class class
• A new class (sub class) can be derived from the super class
with some additional features in addition to the features in the
super class
More General
Vehicle Abstraction
General Abstraction
More Generalized
class
Specialization
Generalization
Super class
More Specialized
Sub class class
appearance
Butterfly Stage
appearance
Person Stage
1 implements 1
IEEE Member Member Type
ce
classification
an
Person
it
er
– Single inheritance
inh
– Multiple inheritance
le
ng
Si
Student Employee
• Delegation is the ability of an object
ce
tan
to issue a message to another
eri
objects in response to a message
Inh
le
Research
ltip
• Delegation is an alternative to Scholar
Mu
inheritance
Example :
– Real world
Water has two forms: solid (ice) and liquid (water)
– Algebra
z = z1 + z2 * z3 + a * 5 – z4
IEEE Executive
.
.
.
.Profile()
10 August, 2006 Information System Design IT60105, Autumn 2006
Binding
• Binding closely related to Polymorphism
Example:
B1 B2
•name •name
•display(<<name>>) •display(<<name>>)
display(){
print “regnNo”
D
•regnNo B1::display()
•display() print “B2::name”
}
– In d2.display ( ): name
from D1, regnNo from D1
D2 •name
•display()
– Note: here d1, d2 are
object of D1, D2 classes
respectively
D2
•regnNo
10 August, 2006 Information System Design IT60105, Autumn 2006
•enroll()
Problem to Ponder
B
a
D 1 D 2
a o f B a o f B
C
a o f B b y D 1 ?
a o f B b y D 1 ?
A m b i g u o u s U n a m b i g u o u s