Professional Documents
Culture Documents
Class Compatibility
A
class is behaviorally compatible with another if it supports all the operations of the other class a class is called subtype
Such
Class Compatibility
Derived
class is usually a subtype of the base class can handle all the legal messages (operations) of the base class
It
Therefore,
Circle
radius draw computeArea
Triangle Line
length draw getLength
ASCII File
print
Polymorphism
In
For
Polymorphism in OO Model
In
OO model, polymorphism means that different objects can behave in different ways for the same message (stimulus)
sender of a message does not need to know exact class of the receiver
Consequently,
Example Polymorphism
Shape draw Circle draw Triangle draw
View
draw
Line draw
Example Polymorphism
File print PDF File print PS File print
Editor
Polymorphism Advantages
Messages
View
draw
Line draw
Polymorphism Advantages
New
View
draw
Square draw
Line draw
Polymorphism Advantages
In
Object-Oriented Modeling
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
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
Eliminate Editor User
irrelevant classes
Identify Classes
Add
Group
Individual shapes can be grouped together and can behave as a single shape
View
Identify Classes
Following classes have been identified:
Shape
Line
Circle Triangle Menu
Group View
Line
Menu
Circle
View Triangle
Identify Associations
Extract
Identify Associations
Verify View
access paths
contains shapes
lines circles triangles groups
Identify Associations
Verify Menu
Line n
n Circle
n Triangle
Identify Attributes
Extract
Identify Attributes
Extract
Line
Color Vertices Length
Circle
Color Vertices Radius
Shape
Color Vertices
Identify Attributes
Extract
Group
noOfObjects
View
noOfObjects selected
Group noOfObjects
Identify Operations
Extract
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 Operations
Eliminate Develop Behave
irrelevant operations
Identify Operations
Following
Line
Draw Select Move Rotate
Identify Operations
Following
Triangle
Draw Select Move Rotate
Identify Operations
Following
Group
Draw Select Move Rotate
Identify Operations
Extract
View
View noOfObjects selected add() remove() group() show() select() move() rotate() Line n length draw() n n Triangle angle n n draw() draw()
n
Group noOfObjects draw()
n Circle radius
Identify Inheritance
Search
Identify Inheritance
By
analyzing requirements
Individual
of inheritance demands an iteration over the whole object model the inheritance hierarchy,
All attributes are shared All associations are shared Some operations are shared Others are overridden
In
associations
Group
Color, vertices
Shape
Draw
View noOfObjects selected add() remove() group() show() select() move() rotate()
View noOfObjects selected add() remove() group() show() select() move() rotate() Line n length draw() n n Triangle angle n n draw() draw()
n
Group noOfObjects draw()
n Circle radius