OOP - Object Oriented Paradigm
OOP - Object Oriented Paradigm
Strictly for internal circulation (within KIIT) and reference only. Not for outside circulation without permission
Lecture Note
3 Credit Mr. Rajat Behera - Associate Professor
Course Outcome
2
• Concept of inheritance: defining derived and base classes, Class hierarchies, public,
private, and protected derivations
• Types of Inheritance: Single Inheritance, Multilevel Inheritance, Multiple Inheritance,
Hierarchical Inheritance, Hybrid Inheritance
• Virtual base class: Function overriding
• Constructors/Destructors in derived classes: Constructors invocation and data
members initialization in derived classes
• Member classes: classes within classes
6 Operator Overloading 3
Textbook
Object Oriented Programming with C++ by Reema Thareja, 2nd Edition
Reference Books
Object Oriented Programming with C++, E. Balaguruswamy, 7th Edition, 2013 TMG
Hill
C++ completes reference, Herbert Schildt, TMG Hill, 4th Edition, 2002.
C++ How to Program, Deitel and Deitel, Pearson Education Asia, 8th Edition, 2011.
Object Oriented Programming with Ansi and Turbo C++, Ashok N Kamthane,
Pearson Education, 1st Edition, 2003.
Programming Paradigm
Paradigm means methodology.
A programming paradigm is a fundamental style of computer programming or the
programming technique that defines how the structure and basic elements of a
computer program is built.
While some programming languages strictly follow a single paradigm, others may
draw concepts from more than one.
Types of Programming Paradigm
Monolithic Programming – emphasizes on finding a solution
Structured Programming – focus on modules
Procedure-oriented Programming – lays stress on algorithms
Object-oriented Programming – emphasizes on classes and objects
Structured Programming
Programming tasks can be split into smaller sections known as functions or
subroutines, which can be called whenever they are required.
It is often (but not always) associated with a “top down” approach to design.
It attempts to divide the problem into smaller blocks or procedures which interact
with other.
The aim is to clearly define the structure of the program before writing program code.
Examples: Pascal, Ada, C
Procedure-oriented Programming
It basically consists of writing a list of instructions for the computer to follow and
organizing these instructions into groups known as functions.
The primary focus is on functions.
Examples: COBOL, FORTRAN
Characteristics
Emphasis is on doing things (algorithms)
Larger 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
Relationship of data and functions
It treat 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 build data functions around these objects
The data of an object can be accessed only by the functions associated with that object.
Functions of one object can access the functions of another objects
Organization of data and functions
Characteristics
Emphasis is on data rather than procedure.
Programs are divided into 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 can not be accessed by external
functions.
Objects may communicate with each other through
functions.
New data and functions can be added easily whenever
necessary.
Follows bottom-up approach in program design
School of Computer Engineering
Basic Concepts
17
The object oriented language supports mechanism to define, create, store and
manipulate objects and allow communication between objects. Some of the
concepts are as follows -
Classes
Objects
Data abstraction
Encapsulation
Inheritance
Polymorphism
Dynamic Binding
Message Passing
Overloading
Class?
Objects?
Note
Data abstraction refers to providing only essential information to the outside world
and hiding their background details, i.e. to represent the needed information in
program without presenting the details.
Example - TV, which you can turn on and off, change the channel, adjust the volume,
and add external components such as speakers, VCRs, and DVD players, BUT you do
not know its internal details, that is, you do not know how it receives signals over the
air or through a cable, how it translates them, and finally displays them on the screen.
Thus, we can say a television clearly separates its internal implementation from its
external interface and you can play with its interfaces like the power button, channel
changer, and volume control without having zero knowledge of its internals.
Another Example - Okay. Bank does
not need all these
customer information
for the business.
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.
Each derived class shares common characteristics with the class from which
it is derived.
The main benefits of the Inheritance is code reusability i.e. add additional
features to an existing class without modifying it.
Polymorphism is a Greek term and it means the ability to take more than one
form.
An operation may exhibit different behaviors in different instances and the
behavior depends upon the type of data used in the operation.
Example –
For adding two number operation will generate sum of two number.
For adding two string operation will concanete two string.
Add(3, 5) gives 8 and Add(“hello”, “world”) gives “hello world”
Happens at Happens at
compile time run time
Dynamic binding ( 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.