Introduction To Object Oriented Programming
Introduction To Object Oriented Programming
Programming
Procedure Oriented Programming
Conventional Programming, using high-level
languages such as COBOL, FORTRAN and C, is
commonly known as Procedure Oriented
Programming (POP).
In POP approach, the problem is viewed as a
sequence of things to be done as reading,
calculating and printing.
A number of functions are written to
accomplish these tasks.
The primary focus is on functions.
Characteristics of POP:
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.
Disadvantage of POP:
◦ In a large program, it is very difficult to identify which data is used by which function. In case we
need to revise an external data structure, we also need to revise all the functions that access the
data. This provides an opportunity for the bugs to creep in..
◦ It does not model real world problems very well. This is because the functions are action oriented
and do not really correspond to the elements of the same problem.
Object Oriented Programming
This approach was invented to remove some of the flaws of POP.
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 other functions.
OOP allows decomposition of problem into number of entities called Objects and than 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.
Features of OOP
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 data of an object are tied together in the data structures.
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.
Data:
Name
Date-of-birth
Marks
Functions:
Total
Average
Display
Classes
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.
Once a class has been defined, we can create any number of objects of that class.
Each object is associated with the data of type class with which they are created.
A class is thus a collection of objects of similar type.
Classes are user defined data types and behaves like the built in data types of a
programming language.