You are on page 1of 13

eÁw

CHAPTER 6
Object Oriented Concepts

OBJECTIVES
To Understand the basic concepts of Object Oriented Methodology

133
134
Object Oriented Concepts

6.1 Introduction and Evolution of programming languages


The computer technology has evolved at such a fast rate that yesterday’s (i.e., some 25 years ago)
eÁw
mainframes are today’s personal computers. The software industry is also growing at the same
rate proportionally. The operations are becoming more and more complex but, more user friendly, and the
software engineers felt that it was difficult to implement these complex designs using traditional
programming languages (i.e., procedural languages or structured programming languages). The
programming languages that adopted the procedural and structured programming approach were PASCAL,
C, COBOL, etc. Generally these languages deal with two important aspects – data and algorithm.
Data is the main substance of the program and the algorithms are the methods that use these
programs. They found that these traditional methods of programming was lengthy, expensive,
error prone, lacked reusability, difficult to maintain and sometimes even disastrous. Therefore, this lead
to the revival of the third generation languages and the result was the fourth generation which
further gave birth to the fifth generation languages which was called as Object Oriented Programming
System concepts (OOP).

6.1.1 Procedural Programming


The procedural programming focuses on processing of instructions in order to perform a desired
computation. Therefore it emphasizes more on doing things i.e. on algorithms. Programming using
procedural languages set a threat as the length and complexity of the problem increased. For example,
procedural programs make use of branching statements, where the flow of control changes its path according
to the result of the test expression. Many programs had these routing and it was difficult to understand
and modify them.

6.1.2 Structured Programming


The difficulties in procedural programming languages gave a way to the scientists to develop
C language which was better language when compared to the procedural languages. It gave a new idea
of programming approach called as “Structured Programming”. Structured Programming
approach was a disciplined approach which limited the branching to a small set of well-behaved
construction (i.e., if – else statement, for loop, while loop, do while loop and so on). C followed the
top-down principle of programming. The idea of Top-down design is to break a large program into
smaller programs, and the smaller programs into still smaller sub-programs further until it can be
implemented for computer solution. However, the structured programming technique reflected the
procedural programming method itself, because it lacked the required clarity, reliability and ease of
program maintenance as the program length grew in its size. The major drawback of both the
procedural and structured programming is that it is very difficult to model the real world using these
methods.

135
Object Oriented Concepts

6.1.3 Object oriented Programming


OOP emphasizes on data unlike the structured programming which emphasizes on program. i.e., the
ideology here is to unite both the data and the functions that operate on that data into a single unit called as
"object". This can be pasteurized as shown in fig 6.1.

Object X Object Y

Data Data

Functions Functions

Object Z

Data

Functions

Figure 6.1 Objects

Therefore, an object is an identifiable entity with some characteristics and behavior.

Object Oriented Programming (OOP) is a concept that combines both the data and the functions
that operate on that data into a single unit called the object.

Object is an identifiable entity with some characteristics and behavior.

Top-down design is an approach of dividing a problem into sub problems and then dividing the
sub problems further into still smaller sub problems until it can be implemented for a computer
solution.

Bottom up design is the vice versa where solutions to smaller modules are integrated together to find
the solution of the overall program.

136
Object Oriented Concepts

Object oriented approach is simple and improves software reusability. OOPs view any problem as
object rather
eÁw
than as a procedure. For example, we can say ‘mobile’ is an object and its characteristics
are colour, weight, display, size etc. Its features include price, voice call, video call, memory size etc. Here
OOP considers the characteristics as data and features as functions.
Furthermore, OOP follows ‘Bottom-Up’ approach of programming which is exactly the vise-
versa of the Top-Down approach. Here, in Bottom-Up approach we integrate the solution of smaller
subprograms together in order to find the solution of the overall entire program.
Another important concept with respect to OOP is the ‘Class’. A class serves as a plan or blueprint
that specifies what data and what functions should be included in the objects of that class.

A class is a template that represents a group of objects which share common properties and
relationships.

6.2 OOPs characteristics


OOPs was designed in order to overcome the drawbacks of structured, modular programming
approach. The general concepts of OOPs includes
 Modularity
 Abstraction
 Data Encapsulation
 Inheritance
 Polymorphism
 Dynamic binding
 Message Passing

6.2.1 Modularity
Module: It is a logically self-contained unit that can be tested and executed independently.
Modularity: It is a technique adopted to divide a complex problem into a number of self-contained
independent program segments.

The very idea of dividing or partitioning the program in to smaller sub programs is to
reduce the complexity of the program to certain extent. Modularity helps in achieving this. It also helps
in creating clear cut boundary within a program. A module is a self-contained independent
unit of a program and it can be tested and executed separately even if it is has link with other
modules. For example, let us consider a mobile phone. It will have other features such as a camera to
take still picture or even to make a video, FM to tune on to listen to various channels, internet,
speaker, and memory to store. All of these units are independent modules for capturing pictures, for
listening to radio, sending mail…..etc. Therefore, this is what we actually call modularity. All of these
units are placed inside a case called the mobile phone. Similarly, in object oriented programming
the classes and objects form the logical structure of a system. As the complexity and the length of the
program increases we need to place them in logically contained units called the classes. C++ which is
object oriented programming language implements modularity by placing the programs in units
137
Object Oriented Concepts

called header files and these modules can be included in our application programs also. We need to
include them along in the macro using "#include". These files have an extension of .h and are called
header files. For example,
#include "iostream.h"
#include "math.h" etc.

Here #include is a macro and iostream and math are modules that contain some related files which
can be included in our application programs easily.

6.2.2 Abstraction
Abstraction is an act which represents the essential features of an entity without including explanations
or any background details about it.

This is one of the important characteristics adopted in all programming languages and OOP
implements abstraction using classes as a list of abstract attributes. Let us consider the same example of
the mobile phone. The attributes include the colour, Bluetooth, built in camera etc, we are not
considering how the Bluetooth works, or how the camera works or even how the circuit inside the mobile
is designed and what is happening inside. We are interested only in using the mobile and its features.
Therefore it is required to know how to operate the mobile phone and its other features without knowing
the background details of its design aspects.

6.2.3 Data Encapsulation


The wrapping of data and functions into a single unit called as class known as
encapsulation.
The concept of insulating the data from direct access by the program is called data
hiding

Another important feature of OOP is data encapsulation of a class. The wrapping of data and func-
tions into a single unit called as the class is known as encapsulation. The data is not directly accessible to
the outside world, except for those functions which are wrapped in the class. These functions provide
interface between the object’s data and the program. It is because of this feature that the data seems to be
hidden.

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

138
Object Oriented Concepts

OOP support the feature of inheritance to provide the idea of reusability. It is possible to add additional
featureseÁw
to an existing class without modifying it. It supports the concept of hierarchical classification and
the new class is derived from an existing class. Therefore the new class will have the combined features of
both the classes. The fig 1.2 explains the inheritance where we find that student is a class and PUC
student and MBA STUDENT are sub classes derived out of the class student. Each sub class defines only
those features unique to it.

STUDENT

Attributes
Register No.
Name
Class

PUCSTUDENT MBASTUDENT

Attributes Attributes
Marks Grade
Subject Code Electives
………. ………..

Figure 6.2 Inheritance

6.2.5 Polymorphism
Polymorphism is the ability for a message to be processed in more than one form.
The process of making an operator to exhibit different behaviors 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 is another important concept of OOPs. It is derived from the Greek word, which
means to take more than one form. Just like how the human mind’s thinking pattern keeps changing, an
operation may also behave differently at different instances and the behavior depends on the types of data
used in the operation. For example, the addition operator can be used for adding numbers and also to
concatenate strings.Fig6.3 shows how the single function name is used to handle types and different
number of arguments.

139
Object Oriented Concepts

house object college object

Paint(house) Paint(college)

Items

Paint()

furniture object fabric object

Paint(furniture) Paint(fabric)

Figure 6.3 Polymorphism

Polymorphism allows objects to have different internal structures to share the same external interface.
It supports to implement inheritance to a great extent.

6.2.6 Dynamic Binding

Binding means 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. It is associated with polymorphism and inheritance.

A function call that has association with polymorphism depends on the dynamic type of that reference.
We find that each object will have its own task to perform, however it gets redefined to do some other
task when it is used in other class that uses this object. For example, in the fig.6.3 of polymorphism, we
find that the procedure paint ( ) is used to paint a college, house etc, and the procedure will be redefined
in each of these objects.

140
Object Oriented Concepts

6.2.7 Message Passing


In eÁw
OOPs concept message means a request for execution of a procedure for an object. Therefore a
message invokes a procedure in the receiving object to generate the desired output. For example, let us
consider that we have created an object by name ‘college’ and we have calculated the ‘result’
(information) of students by taking their marks (message) into consideration then it is possible to pass
message to this object as represented in the below fig.6.4

college.marks( result)

object message information

Fig. 6.4 Message passing

6.3 OOPs Benefits


OOPs is indeed a very beneficiary tool which help in efficient programming, because the very idea
of using OOPs technique was to overcome the drawbacks of procedural and structured programming
approach. This new technology provides the programmer with greater productivity, quality software at a
less maintenance cost. The major advantages include
 OOPs model the real world entities very well.
 Inheritance extends the use of existing classes and eliminates redundant code hence supports
code reusability.
 Data hiding helps to build secure programs that cannot be invaded by code in other parts of the
program.
 Multiple instances of an object co exist without any interference.
 The work can be divided easily since the projects are object based and each object can be
developed by different people resulting in faster code development.
 OOPS can be easily upgraded from small to large systems.
 Complexity of the software is easily manageable, tested and maintained.
 It is possible to map objects from the problem domain to program domain.
 Message passing technique for communication between the objects makes the interface
description simpler with external systems.
 Standard working modules communicate with one another and we can therefore build programs
from these modules which save development time and increases productivity.
 Data centered design approach helps to capture more details of the model in implementable
form.
We should understand one thing that to develop software, that is easy to use is extremely difficult and
even next to impossible. However object oriented programming tools helps to achieve this to some extent.

141
Object Oriented Concepts

6.4 OOP disadvantages


Every aspect in the universe has both advantages and disadvantages. But we need to understand that
when the percentage of advantages is more compared to disadvantages then there is no harm in accepting
it. However the disadvantages of OOPs are less and are identified below.
 OOPs use tricky methods to do the programming.
 Special skills such as thinking in terms design skills, programming skills and thinking in terms of
objects, are required for a programmer.
 Proper planning and design is required before programming using OOPs technique.

6.5 OOPs Applications


After coming to know the benefits it is required to know the applications also. The most popular
application of OOPs has been in the area of ‘user interface design’ of windows operating system. Many
of the windowing systems have been developed using this technique. Real time systems and embedded
systems are developed using complex attributes and methods. Some of the areas for applications of
OOPs are:
 Object oriented databases.
 Hypermedia, expert text and hypertext.
 Artificial Intelligence and expert systems.
 Decision support systems and office automation systems.
 Parallel programming and neural networks.
 CAD, CAM, CIM systems.
 Simulation and modeling.

Henceforth the OOPs approach has actually improved the quality of software and also has increased
productivity. This approach has magically brought about an evolution in the software world.

142
Object Oriented Concepts

Review Questions:
eÁw
One mark questions:
1. Define Structured Programming.
2. Define Top-down design.
3. What is Bottom up?
4. What is Top-down?
5. Define an Object.
6. What is Object Oriented Programming (OOP)?
7. What is Class?
8. Define a Module.
9. What is Bottom up approach?
10. What is Modularity?
11. What is Abstraction?
12. What is Data Encapsulation.?
13. What is Inheritance?
14. What is Polymorphism?
15. What is Dynamic binding?
16. What is Message Passing?
17. Mention any one benefit of OOP.
18. Mention any one advantage of OOP.
19. Mention any one disadvantage of OOP.
20. Mention any one application of OOP.

Two marks questions


1. Differentiate between structured programming and object oriented programming.
2. Mention any two characteristics of OOP.
3. Briefly explain about Data Encapsulation.
4. Briefly explain about Inheritance.
5. Briefly explain about Polymorphism.
6. Briefly explain about Dynamic binding.
7. Briefly explain about Message Passing.
8. Mention any two benefits of OOP.
9. Mention any two OOP advantages of OOP.
10. Mention any two OOP disadvantages of OOP
11. .Mention any two OOP applications of OOP.

Three marks questions


1. Explain in detail about any four characteristics of OOP.

143
Object Oriented Concepts

2. Explain in detail about Data Encapsulation and Inheritance.


3. Explain in detail about Polymorphism and Dynamic binding.
4. Briefly explain about Dynamic binding and Message Passing.
5. Mention any two advantages and two disadvantages of OOP.
6. Mention any four advantages of OOP.
7. Mention any four benefits of OOP.
8. Mention any four applications of OOP.

Five marks questions:


1. What is OOP? Describe in detail the various characteristics of OOP with suitable examples.
2. Mention the various advantages and two disadvantages of OOP.
3. Mention the various applications of OOP.
4. Mention the various benefits of OOP.

144

You might also like