Concepts Related with Inheritance - Object Oriented Programming - Lecture Slides, Slides of Object Oriented Programming

Concepts Related with Inheritance, Generalization, Subtyping, Extension, Specialization, Restriction, OO models, Original classes, Overriding, Reasons for overriding 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 / 26

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Object-oriented Programming
(OOP)
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Concepts Related with Inheritance - Object Oriented Programming - Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

Object-oriented Programming

(OOP)

Recap – Inheritance

• Derived class inherits all the

characteristics of the base class

• Besides inherited characteristics, derived

class may have its own unique

characteristics

• Major benefit of inheritance is reuse

Generalization

• In OO models, some classes may have

common characteristics

• We extract these features into a new class

and inherit original classes from this new

class

• This concept is known as Generalization

Example – Generalization

Circle

color vertices radius move setColor computeArea

Line

color vertices length

move setColor getLength

Triangle

color vertices angle move setColor computeArea

Example – Generalization

Teacher

name age gender designation salary teach takeExam eat walk

Student

name age gender program studyYear study heldExam eat walk

Doctor

name age gender designation salary checkUp prescribe eat walk

Example – Generalization

Person

name age gender eat walk

Teacher

designation salary teach takeExam

Student

program studyYear

study heldExam

Doctor

designation salary checkUp prescribe

Sub-typing (Extension)

• Sub-typing means that derived class is

behaviourally compatible with the base

class

• Behaviourally compatible means that base

class can be replaced by the derived class

Example –

Sub-typing

(Extension)

Person

name

age

gender

eats

walks

Student

program

studyYear

study

takeExam

Specialization (Restriction)

• Specialization means that derived class is

behaviourally incompatible with the base

class

• Behaviourally incompatible means that

base class can’t always be replaced by the

derived class

Example – Specialization

(Restriction)

Person

age : [0..100] …

Adult

age : [18..100] …

setAge( a ) …

setAge( a ) …

age = a

If age < 18 then error else age = a

Overriding

• A class may need to override the default

behaviour provided by its base class

• Reasons for overriding

  • Provide behaviour specific to a derived class
  • Extend the default behaviour
  • Restrict the default behaviour
  • Improve performance

Example – Specific Behaviour

Shape

color vertices draw move setColor

Circle

radius

draw computeArea

Line

length draw

Triangle

angle draw computeArea

Example – Restriction

IntegerSet

NaturalSet

add( elem ) …

add( elem ) …

Add element to the set

If elem < 1 then give error else Add element to the set

Example – Improve Performance

  • Class Circle overrides

rotate operation of

class Shape with a

Null operation.

Shape

color coord draw rotate setColor

Circle

radius draw rotate