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

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)

115 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 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)