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

Main topics in this course are object-orientation, objects and classes, overloading, inheritance, polymorphism, generic programming, exception handling, introduction to design patterns. This lecture includes: Class, Compatability, Subtype, Operation, Behaviour, Polymorphism, Model, Advantage, Reciever, Draw

Typology: Slides

2011/2012

Uploaded on 08/08/2012

anchita
anchita 🇮🇳

4.4

(7)

113 documents

1 / 43

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
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b

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)