Professional Documents
Culture Documents
CHAPTER 6
Object Oriented Concepts
OBJECTIVES
To Understand the basic concepts of Object Oriented Methodology
133
134
Object Oriented Concepts
135
Object Oriented Concepts
Object X Object Y
Data Data
Functions Functions
Object Z
Data
Functions
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.
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.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.
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
………. ………..
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
Paint(house) Paint(college)
Items
Paint()
Paint(furniture) Paint(fabric)
Polymorphism allows objects to have different internal structures to share the same external interface.
It supports to implement inheritance to a great extent.
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
college.marks( result)
141
Object Oriented Concepts
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.
143
Object Oriented Concepts
144