OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING

 

Object-oriented programming (OOP) , there are three major language features; ADT, Inheritance (inheritance is the central theme in OOP an language that support it, Polymorphism. Inheritance can increase productivity by reuse. ADTs are difficult to reuse-always need change, all ATDs are independent and at the same level.

Object-Oriented Concept

  • ADTs are usually called classes
  • Class instances are called objects
  • A class that inherits is a derived class or a subclass
  • The class from which another class inherits is a parent class or superclass
  • Subprograms that define operations on objects are called methods
  • Calls to methods are called messages
  • The entire collection of methods of an object is called its message protocol or message interface
  • Messages have two parts–a method name and the destination object
  • In the simplest case, a class inherits all of the entities of its parent
  • Inheritance can be complicated by access controls to encapsulated entities
    1. A class can hide entities from its subclasses
    2. A class can hide entities from its clients
    3. A class can also hide entities for its clients while allowing its subclasses to see them
  • Besides inheriting methods as is, a class can modify an inherited method
    1. The new one overrides the inherited one
    2. The method in the parent is overriden
  • Three ways a class can differ from its parent:
  1. The parent class can define some of its variables or methods to have private access, which means they will not be visible in the subclass
  2. The subclass can add variables and/or methods to those inherited from the parent
  3. The subclass can modify the behavior of one or more of its inherited methods.
  • There are two kinds of variables in a class:
    • Class variables – one/class
    • Instance variables – one/object
  • There are two kinds of methods in a class:
    • Class methods – accept messages to the class
    • Instance methods – accept messages to objects
  • Single vs. Multiple Inheritance
  • One disadvantage of inheritance for reuse:
    • Creates interdependencies among classes that complicate maintenance

 

 

Design issues for OOP

  • The exclusivity of objects, everything is an object, add objects to a complete typing system, include an imperative-style typing system for primitives but make everything else objects.
  • Are subclases subtypes, If a derived class is-a parent class, then objects of the derived class must behave the same as the parent class object. Subclass can only add variables and methods and override inherited methods in “compatible” ways.
  • Single and multiple ineritance, multiple inheritance allows a new class to inherit from to or more classes. The disadvantages is language and implementation complexity. The Advantage it is quite convenient and valuable.
  • Object allocation and deallocation, If they behave line the ADTs, they can be allocated from anywhere. If they are all heap-dynamic, references can be uniform thru a pointer or reference variable. If objects are stack dynamic, there is a problem with regard to subtypes – object slicing.
  • Dynamic and static binding,

Should all binding of messages to methods be dynamic?

  • If none are, you lose the advantages of dynamic binding
  • If all are, it is inefficient

Maybe the design should allow the user to specify

  • Nested classes, If a new class is needed by only one class, there is no reason to define so it can be seen by other classes.

Support for OOP in C++,

  • General Characteristics:
    • Evolved from C and SIMULA 67
    • Among the most widely used OOP languages
    • Mixed typing system
    • Constructors and destructors
    • Elaborate access controls to class entities

 

  • Implementation of Object-Oriented Constructs Two interesting and challenging parts; Storage structures for instance variables, dynamic binding of messages to methods.

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *