Object-Oriented Programming (OOP) Lecture No. 6
Object-Oriented Programming (OOP) Lecture No. 6
(OOP)
Lecture No. 6
Class Compatibility
►A class is behaviorally compatible with
another if it supports all the operations of
the other class
Circle Triangle
radius Line angle
length
draw draw
computeArea draw computeArea
getLength
Example – Class Compatibility
File
size
…
open
print
…
draw Shape
View
draw
print File
Editor
print
draw Shape
View
draw
draw Shape
View
draw
An Example
Problem Statement
► Develop a graphic editor that can draw
different geometric shapes such as line,
circle and triangle. User can select, move or
rotate a shape. To do so, editor provides
user with a menu listing different
commands. Individual shapes can be
grouped together and can behave as a
single shape.
Identify Classes
Extract nouns in the problem statement
► Shape • Group
► Line • View
► Circle
► Triangle
► Menu
Object Model – Graphic Editor
Shape Group
Line Menu
Circle
View
Triangle
Identify Associations
Extract verbs connecting objects
nn nn nn
Line nn Circle Triangle Group
nn
nn nn
Identify Attributes
Extract properties of the object
From the problem statement
• Line • Triangle
– Color – Color
– Vertices – Vertices
– Length – Angle
• Circle • Shape
– Color – Color
– Vertices – Vertices
– Radius
…Identify Attributes
Extract properties of the object
From the domain knowledge
• Group • Menu
– noOfObjects – Name
• View – isOpen
– noOfObjects
– selected
Object Model – Graphic Editor
n n n
Line n Circle Triangle Group
length radius angle noOfObjects
n
n
n
Identify Operations
Extract verbs connected with an object
• Line • Circle
– Draw – Draw
– Select – Select
– Move – Move
– Rotate – Rotate
…Identify Operations
Following are selected operations:
• Triangle • Shape
– Draw – Draw
– Select – Select
– Move – Move
– Rotate – Rotate
…Identify Operations
Following are selected operations:
• Group • Menu
– Draw – Open
– Select – Select
– Move – Move
– Rotate – Rotate
…Identify Operations
Extract
operations using domain
knowledge
• View
– Add – Select
– Remove – Move
– Group – Rotate
– Show
View
Menu noOfObjects Shape
selected
name color
isOpen vertices
add()
remove()
open() n draw()
group()
select() select()
show()
move() move()
select()
rotate() rotate()
move()
rotate() n
n n
Line n Triangle Group
n
length angle noOfObjects
Circle
n
draw() radius draw() draw()
n
n draw()
Identify Inheritance
By analyzing requirements
► “Individual
shapes can be grouped together
and can behave as a single shape”
Group inherits from Shape
Refining the Object Model
► Applicationof inheritance demands an
iteration over the whole object model
Share associations
Share attributes
Share operations
n n
Line n Triangle Group
n
length angle noOfObjects
Circle
n
draw() radius draw() draw()
n
n draw()