Chapter 2 : Principles of object oriented programming



Object -oriented programming paradigm :
Object-oriented programming is 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.OOP allows us to decompose a problem into a number of entities called objects and then builds data and functions around these entitles. The organization of data and functions in object-oriented programs shown in fig.

The data of an object can be accessed only the functions associated with that object. However, functions of one object can access the functions of other object.
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.

The data of an object can be accessed only the functions associated with that object. However, functions of one object can access the functions of other object.
Basic concepts of object-oriented programming :
'Object-oriented' remains a term which is interpreted differently by different people. We shall discuss in this section the following general concepts :
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 or any item that the program must handle.

Class
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 class. In fact, objects are variables of type class.

Data abstraction and Data encapsulation
The wrapping up of data and functions into a single unit called (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 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.
Abstraction refers to the act of representing essential features without including the background details or explanations. Class encapsulate all the essential properties of the objects that are to be created. Since the classes use the concept of data abstraction, they are known as Abstract Data Types (ADT).

Inheritance
Inheritance is the process by which objects of one class acquire the properties of objects of another class.

Polymorphism
Polymorphism is another important OOP concept. Polymorphism means the ability to take more than one form. 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.

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 the call at run-time.

Message passing
An object-oriented program consists of a set of objects that communicate with each other. The process of programming in an object-oriented language therefore involves the following basic steps :
1. Creating classes that define objects and their behaviour.
2.Creating objects from class definitions.
3.Establishing communication among objects.

Benefits of OOP :
OOP offers several benefits to both the program designer and the user. The new technology promises greater programmer productivity, better quality of software and lesser maintenance cost. The principal advantages are :

Thought inheritance, we can eliminate redundant code and extend the use of existing classes.

We can build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch. This leads to saving of development time and higher productivity.

The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program.

It is possible to have multiple instances of an object to co-exist without any interference.

It is possible to map objects in the problem domain to those objects in the program.

It is easy to partition the work in a project based on objects.

The data-centered design approach enables us to capture more details of a model in implementable form.

Object-oriented systems can be easily upgraded from small to large systems.

Message passing techniques for communication between objects makes the interface descriptions with external systems much simpler.

Software complexity can be easily managed.