slide1 l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
OOPs PowerPoint Presentation
Download Presentation
OOPs

Loading in 2 Seconds...

play fullscreen
1 / 21

OOPs - PowerPoint PPT Presentation


  • 114 Views
  • Uploaded on

OOPs. Object oriented programming. Abstract data types. Representationof type and operations in a single unit Available for other units to create variables of the type Possibility of hiding data structure of type and implementation of operations. Limitations of ADT and OOP extensions.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'OOPs' - redell


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

OOPs

Object oriented programming

abstract data types
Abstract data types
  • Representationof type and operations in a single unit
  • Available for other units to create variables of the type
  • Possibility of hiding data structure of type and implementation of operations
limitations of adt and oop extensions
Limitations of ADT andOOP extensions
  • Software reuse: ADTs too rigid

-> inheritance

  • No structure to collections of ADTs

-> inheritance

OOP provides class hierarchies

the three hierarchies of oop
The three* hierarchies of OOP
  • Inheritance:

1 - n

  • Instantiation

1 - n

  • Composition

1 - n

superclass

subclass

class

instance

object

instance variable

* Not including interfaces

inheritance
Inheritance
  • Superclass – subclass
    • Subclass inherits all methods, variables
    • Subclass can add methods, variables
    • Subclass can overwrite all methods, variables

-> increased reusability

-> structure collections of classes

access to variables and methods
Access to variables and methods
  • ADTs – public (global scope) or private (class scope)
  • Objects - public or private

-plus protected (class plus subclasses)?

Design decision: info hiding vs efficiency

  • Java adds package scope
inheritance rules
Inheritance rules
  • Single inheritance (Smalltalk) – subclass has only one superclass; classes form an inheritance tree
  • Multiple inheritance (C++) – subclass can have multiple superclasses
  • Single inheritance plus interfaces (Java)
need for multiple inheritance
Need for multiple inheritance
  • ‘orthogonal’ properties – the ‘diamond’ problem

Vehicle

GMVehicle

KiaVehicle

Car, SUV properties repeated

Manufacturer properties repeated

GMCar

GMSUV

KiaCar

KiaSUV

Vehicle

Car

SUV

GMCar

KiaCar

GMSUV

KiaSUV

using multiple inheritance
Using multiple inheritance

Vehicle

GMVehicle

KiaVehicle

Car

SUV

GMCar

GMSUV

KiaCar

KiaSUV

problems of multiple inheritance
Problems of multiple inheritance
  • Identifier conflict:

Class Super1

int x, y

Class Super2

double x, z

Class Sub extends Super1, Super2

Which x?

interfaces solve the multiple inheritance problem
Interfaces solve the multiple inheritance problem
  • No variables in interfaces
  • No method implementations in interfaces – only protocols

BUT

  • Weaker inheritance – no gain in code reuse
type checking
Type checking
  • none (Smalltalk typeless)
    • message compatibility
  • subclasses are subtypes*
    • type compatibility – object of subtype can be assigned to identifier declared of superclass type
    • dynamic type checking provides polymorphism

* note exceptions, e.g., C++

polymorphism in method calls
Polymorphism in method calls

Super a,b,c,d;

a = new Super();

b = new Sub1();

c = new Sub2();

d = new Sub3();

a.x();

b.x();

c.x();

d.x();

class Super

method x()

class Sub1

method x()

class Sub2

class Sub3

method x()

polymorphism means dynamic type checking
Polymorphism means dynamic type checking
  • class of object must be determined at run time
    • methods bound to messages dynamically
    • parameters type checked dynamically

BUT

  • protocol can be verified statically

-> purpose of abstract methods

forced static binding
Forced static binding
  • if a method cannot be overridden, it can be statically bound
    • C++ assumes methods cannot be overridden -> statically bound

– virtual keyword causes dynamic binding

    • Java (and Objective C) assumes methods can be overridden -> dynamic binding

– final keyword allows static binding

implementing dynamic method invocation
Implementing dynamic method invocation
  • Superclass method table (VMT)
  • methA
  • methB

Superclass var1;

var1 = new Subclass();

var1.methA();

var1.methB();

var1.methC(); // compile error

  • Subclass method table (VMT)
  • methA
  • methC
  • Ref to parent VMT

Instance vars;

Ref to class VMT

var1

allocation and de allocation
Allocation and de-allocation
  • What kinds of object memory allocation?
    • Static
    • Stack-dynamic
    • Heap-dynamic
  • Heap reclamation
    • Programmer control
    • Garbage collection

C++ Smalltalk,Java

X

X

X X

X

X

slide18
C++
  • Access:
    • Classes private, public
    • Members private, public, protected
  • Extending class can change access
    • Override access to members in parent
    • Valuable for ‘narrowing’ access
    • polymorphism problem

List

Remove some access

Stack

Queue

slide19
C++
  • Inheritance – partial – no single hierarchy
  • Efficient but complex
slide20
Java
  • Closer to pure object language than C++
    • No functions
    • Dynamic by default
    • One hierarchy of classes

BUT

  • Imperative statements
  • Primitive data types are not objects
another object model
Another ‘object’ model
  • Property lists / attribute-value pairs
    • E.g., Lisp symbols: property list
    • E.g., Javascript objects: hash table
    • Properties are typeless – data and methods
    • Set of properties is dynamically varying
    • Ideally suited to tabulation – visual programming
    • Are they objects? ADTs? Variant records?