Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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)

215 documents

1 / 12

Toggle sidebar

Related documents


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

…Class Compatibility

  • Derived class is usually a subtype of the base class
  • It can handle all the legal messages (operations) of the base class
  • Therefore, base class can always be replaced by the derived class

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 general, polymorphism refers to existence of different forms of a single entity
  • For example, both Diamond and Coal are different forms of Carbon

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

Example – Polymorphism

File

ASCII File PDF File PS File print

print

print print

print Editor

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

Polymorphism – Advantages

  • In general, polymorphism is a powerful tool to develop flexible and reusable systems