0% found this document useful (0 votes)
0 views

Chapter 1

Object-Oriented Programming (OOP) integrates structured programming with new concepts to improve program organization by emphasizing data and encapsulation. Key features of OOP include encapsulation, inheritance, polymorphism, and dynamic binding, which allow for modular design and reusability of code. OOP treats objects as the primary entities, enabling better modeling of real-world problems and facilitating communication between objects through defined interfaces.

Uploaded by

Pandu Ranga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Chapter 1

Object-Oriented Programming (OOP) integrates structured programming with new concepts to improve program organization by emphasizing data and encapsulation. Key features of OOP include encapsulation, inheritance, polymorphism, and dynamic binding, which allow for modular design and reusability of code. OOP treats objects as the primary entities, enabling better modeling of real-world problems and facilitating communication between objects through defined interfaces.

Uploaded by

Pandu Ranga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Principles of Object-
Oriented Programming
Object-Oriented Programming (OOP) is an approach to
program organization and development that attempts to
eliminate some of the pitfalls of conventional programming
methods by incorporating the best of structured
programming features with several powerful new concepts.
Procedure-oriented programming basically consists of writing
a list of instructions (or actions) for the computer to follow,
and organizing these instructions into groups known as
functions. While we concentrate on the development of
functions, very little attention is given to the data that are
being used by various functions.

In a multi-function program, many important data items are


placed as global so that they may be accessed by all the
functions. Each function may have its own local data.

Global data are more vulnerable to an inadvertent change by


a function. In a large program it is very difficult to identify
what data is used by which function. In case we need to
revise an external data structure, we also need to revise all
functions that access the data.
This provides an opportunity for bugs to creep in.

Another serious drawback with the procedural approach is


that it does not model real world problems very well. This is
because functions are action-oriented and do not really
correspond to the elements of the problem.

Some characteristics exhibited by procedure-oriented


programming are:
• Emphasis is on doing things (algorithms).
• Large programs are divided into smaller programs known
as functions.
• Most of the functions share global data.
• Data move openly around the system from function to
function.
• Functions transform data from one form to another.
• Employs top-down approach in program design.

OOP treats data as a critical element in the program


development and does not allow it to flow freely around the
system. It ties data more closely to the functions that operate
on it, and protects it from accidental modification from
outside functions. OOP allows decomposition of a problem
into a number of entities called objects and then builds data
and functions around these objects.

The data of an object can be accessed only by the functions


associated with that object. However, functions of one object
can access the functions of other objects.

Some of the striking features of object-oriented programming


are:
• Emphasis is on data rather than procedure.
• Programs are divided into what are known as objects.
• Data structures are designed such that they characterize
the objects.
• Functions that operate on the data of an object are tied
together in the data structure.
• Data is hidden and cannot be accessed by external
functions.
• Objects may communicate with each other through
functions.
• New data and functions can be easily added whenever
necessary.
• Follows bottom-up approach in program design.
We define “object oriented programming as an approach that
provides a way of modularizing programs by creating
partitioned memory area for both data and functions that can
be used as templates for creating copies of such modules on
demand.” Thus, an object is considered to be a partitioned
area of computer memory that stores data and set of
operations that can access that data. Since the memory
partitions are independent, the objects can be used in a
variety of different programs without modifications.

Objects are the basic run-time entities in an object-oriented


system. Programming problem is analyzed in terms of objects
and the nature of communication between them. Program
objects should be chosen such that they match closely with
the real-world objects. Objects take up space in the memory
and have an associated address like a record in Pascal, or a
structure in C.

Each object contains data, and code to manipulate the data.


Objects can interact without having to know details of each
other’s data or code. It is sufficient to know the type of
message accepted, and the type of response returned by the
objects.

We just mentioned that objects contain data, and code to


manipulate that data. The entire set of data and code of an
object can be made a user-defined data type with the help of
a class. In fact, objects are variables of the type class. A class
is thus a collection of objects of similar type. Classes are
user-defined data types and behave like the built-in types of
a programming language.

The wrapping up of data and functions into a single unit


(called class) is known as encapsulation. The data is not
accessible to the outside world, and only those functions
which 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 or information hiding.

Abstraction refers to the act of representing essential


features without including the background details or
explanations. Classes use the concept of abstraction and are
defined as a list of abstract attributes such as size, weight
and cost, and functions to operate on these attributes. They
encapsulate all the essential properties of the objects that
are to be created. The attributes are sometimes called data
members because they hold information. The functions that
operate on these data are sometimes called methods or
member functions.

Since the classes use the concept of data abstraction, they


are known as Abstract Data Types (ADT).
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. The principle behind
this sort of division is that each derived class shares common
characteristics with the class from which it is derived.

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 is another important OOP concept.


Polymorphism, a
Greek term, means the ability to take more than one form. An
operation may exhibit different behaviours in different
instances. The behaviour depends upon the types of data
used in the operation. For example, consider the operation of
addition. For two numbers, the operation will generate a sum.
If the operands are strings, then the operation would produce
a third string by concatenation. The process of making an
operator to exhibit different behaviours in different instances
is known as operator overloading.

Using a single function name to perform different types of


tasks is known as function overloading.

Polymorphism plays an important role in allowing objects


having different internal structures to share the same
external interface. This means that a general class of
operations may be accessed in the same manner even
though specific actions associated with each operation may
differ. Polymorphism is extensively used in implementing
inheritance.

Binding refers to the linking of a procedure call to the code to


be executed in response to the call. Dynamic binding (also
known as late binding) means that the code associated with a
given procedure call is not known until the time of the call at
run-time. It is associated with polymorphism and inheritance.
A function call associated with a polymorphic reference
depends on the dynamic type of that reference.

The process of programming in an object-oriented language


involves the following basic steps:
1. Creating classes that define objects and their behaviour,
2. Creating objects from class definitions, and
3. Establishing communication among objects.

A message for an object is a request for execution of a


procedure, and therefore will invoke a function (procedure) 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.
Object-based programming is the style of programming that
primarily supports encapsulation and object identity. Major
features that are required for object-based programming are:
• Data encapsulation
• Data hiding and access mechanisms
• Automatic initialization and clear-up of objects
• Operator overloading

Languages that support programming with objects are said to


be object-based programming languages. They do not
support inheritance and dynamic binding. Ada is a typical
object-based programming language.

Object-oriented programming incorporates all of object-based


programming features along with two additional features,
namely, inheritance and dynamic binding. Object-oriented
programming can therefore be characterized by the following
statement:
Object-based features + inheritance + dynamic binding

Languages that support these features include C++,


Smalltalk, Object Pascal and Java.

You might also like