Introduction of object oriented programming

Programming practices have evolved considerably over the past few decades.  As more and
more  programmers  gained experience  problems  unknown  hitherto, began  to surface.  The
programming community became ever more concerned about the philosophy that they adopt in
programming and approaches they practice in program development.

Factors like productivity, reliability, cost effectiveness, reusability etc. started to become major
concern.  A lot of conscious efforts were put to understand these problems and to seek possible
solutions.  This is precisely the reason why more and more programming languages have been
developed and still continue to develop.  In addition to this, approaches to program development
have also been under intense research thereby evolving different frame works.  One such, and
probably the most popular one is object-oriented programming approach or simply OOP.

Basic concept of object oriented programming

In object-oriented parlance, a problem is viewed in terms of the following concepts:

  • Objects
  • Classes
  • Data abstraction
  • Data encapsulation
  • Inheritance
  • Polymorphism
  • Dynamic binding
  • Message passing

Objects:  Objects are the basic run-time entities in an object-oriented system. They may
represent a person, a place, a bank account, a table of data; they may also represent user-
defined data such as vectors, time and lists. Each object contains data and code to manipulate the data.

Classes:  A class represents a set of related objects. The object has some attributes, whose value consist much of the state of an object. The class of an object defines what attributes an
object has. The entire set of data and code of an object can be made a user-defined data type
with the help of a class. Classes are user defined data types that behave like the built-in types of a programming language. Classes have an interface that defines which part of an object of a class can be
accessed from outside and how. A class body that implements the operations in the interface, and the instance variables that contain the state of an object of that class.

Objects:  Objects are the basic run-time entities in an object-oriented system. They may
represent a person, a place, a bank account, a table of data; they may also represent user-
defined data such as vectors, time and lists.

Data Abstraction:  Abstraction refers to the act of representing essential-features without
including the background details or explanations. Abstraction is indispensable part of the
design process and is essential for problem partitioning. Partitioning  essentially is the
exercise in determining the components of the system. However, these components are
not isolated from each other, they interact with each other. Since the classes use the concept
of data abstraction, they are known as Abstract Data Types (ADT).

Data Encapsulation:  The wrapping up to data and functions into a single unit (class) is
known as encapsulation. Data encapsulation is the most striking feature of a class. The
data is not accessible to the outside world and only those functions that are wrapped in the
class can access it. These functions provide the interface between the object’s data and the
program. This insulation of the data  from direct access by the program is called data
hiding.

Inheritance:  Inheritance is the process by which objects of one class acquire the properties
of objects of another class. It supports the concept of hierarchical classification. For example,
an manager class is a type of the class employee, which again is a type of the class person
as illustrated below.

The  principle behind  this  sort  of division  is  that  each derived  class  shares  common
characteristics with the class from which it is derived. The power of inheritance lies in the
fact that all common features of the subclasses can be accumulated in the super class. In
other words, a feature is placed in the higher level of abstraction. Once this is done, such
features can be inherited  from the  parent class and used in the  subclass directly. This
implies that if there are many abstract class definitions available, when a new class  is
needed, it is possible that the new class is a specialization of one or more of the existing
classes.

In OOP, the concept of inheritance provides the idea of reusability. This means that we can
add  additional features  to an existing class  without modifying  it. This  is possible  by
deriving a new class from the existing one. The new class will have the combined features
of both the classes.   Each subclass defines only those features that are unique to it. In OOP,
The concept of inheritance provides the idea of reusability. This means that we can add
additional features to an existing class without modifying it. This is possible by deriving
a new class from the existing one. The new class will have the combined features of both
the classes.

Polymorphism:  Polymorphism means the ability to take more than one form. An operation
may exhibit different  behavior in  different instances.  The behavior depends upon  the
types of the data used in the operation.
Dynamic  Binding: Binding refers  to the  linking of  a  procedure call to the  code to  be
executed in response to the call. Dynamic binding means that the code associated with a
given procedure call is not known until the time of call at run-time. This is associated with
polymorphism and inheritance. A function call associated with a polymorphic reference
depends on  the dynamic  type of  that reference.  For example  in the  above figure,  by
inheritance, every object will have this procedure. Its algorithm is, however, unique to
each object so the procedure will be redefined in each class that defines the objects. At
run-time, the code matching the object under reference will be called.

Message Passing:  Message passing is another feature of object-oriented programming. An
object-oriented program consists of a set of objects that communicate with each other. The
concept of message passing makes it easier to talk about building systems that directly
model or simulate their real-world counterparts.

A message for an object is a request for execution of a procedure, and therefore will invoke
a function in the receiving object that generates the desired result. Message passing involves
specifying the name of the object, the name of the function (message) and the information
to be sent.