Docsity

Class Compatibility-Object Oriented Programming-Lecture Slides, Slides of Object Oriented Programming

Partial preview of the text

Download Class Compatibility-Object Oriented Programming-Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

Object-Oriented Programming

(OOP)

Lecture No. 6

Class Compatibility

►

A class is behaviorally compatible withanother if it supports all the operations ofthe other class

►

Such a class is called subtype

►

A class can be replaced by its subtype

Example – Class Compatibility

Shape

colorverticesmovesetColordraw

Circle

radiusdrawcomputeArea

Line

lengthdraw

Triangle

angledrawcomputeArea

Example – Class Compatibility

File

size…openprint…

ASCII File

… print…

PDF File

… print

PS File

… print…

Polymorphism in OO Model

►

In OO model, polymorphism means thatdifferent objects can behave in differentways for the same message (stimulus)

►

Consequently, sender of a message doesnot need to know exact class of the receiver

Example – Polymorphism

Shape

Line

Circle

Triangle

draw

draw draw

draw

draw

View

Polymorphism – Advantages

►

Messages can be interpreted in differentways depending upon the receiver class

Shape

Line

Circle

Triangle

draw

draw draw

draw

draw

View

Polymorphism – Advantages

►

New classes can be added without changingthe existing model

Square

draw

Shape

Line

Circle

Triangle

draw

draw draw

draw

draw

View

Object-Oriented Modeling

An Example

Problem Statement

►

Develop a graphic editor that can drawdifferent geometric shapes such as line,circle and triangle. User can select, move orrotate a shape. To do so, editor providesuser with a menu listing differentcommands. Individual shapes can begrouped together and can behave as asingle shape.

…Identify Classes

Eliminate irrelevant classes

►

Editor – Very broad scope

►

User – Out of system boundary

…Identify Classes

Add classes by analyzing requirements

►

Group – required to behave as a shape

“Individual shapes can be grouped together andcan behave as a single shape”

►

View – editor must have a display area

Object Model – Graphic Editor

Line

Circle

Triangle

Group

Shape

View

Menu

Identify Associations

Extract verbs connecting objects

“Individual shapes can be groupedtogether”

Group consists of lines, circles, triangles

Group can also consists of other groups

(Composition)