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

Class Compatibility, Operations of other class, Subtype, Derived class, Subtype of the base class, Legal messages, Legal operations, Polymorphism, Polymorphism in OO Model are points you can learn in this Object Oriented Programming lecture.

Typology: Slides

2011/2012

Uploaded on 11/09/2012

bacha
bacha 🇮🇳

4.3

(41)

213 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Object-Oriented Programming
(OOP)
Lecture No. 6
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

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 with another if it supports all the operations of the other class
  • Such a class is called subtype
  • A class can be replaced by its subtype

Example – Class Compatibility

Shape color vertices move setColor draw

Circle radius draw computeArea

Line length draw getLength

Triangle angle draw computeArea

Example – Class Compatibility

File size … open print …

ASCII File … print …

PDF File … print …

PS File … print …

Polymorphism in OO Model

  • In OO model, polymorphism means that different objects can behave in different ways for the same message (stimulus)
  • Consequently, sender of a message does not 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 different ways depending upon the receiver class

Shape

Line Circle Triangle draw

draw

draw draw

draw View

Polymorphism – Advantages

  • New classes can be added without changing the existing model

Square draw

Shape

Line Circle Triangle draw

draw

draw draw

draw View