OOP
OOP
Programming Paradigm
Imperative programming
Declarative programming
Structured programming
Procedural programming
Object Oriented programming
Functional programming
Imperative Programming
Imperative programming is the oldest paradigm and is still in practice. It performs step by step
task by changing state through assignment statement. It focuses on what to do and how to do.
Imperative programming lacks the support of modularity. Example: imperative programming languages
are FORTRAN, COBAL, BASIC, JAVA, C programming etc
Declarative Programming
Declarative programming focuses on the logic of software without actually describing the
control flow. Imperative programming defines each steps to get the result whereas declarative
programming defines the logic of computation. Example of declarative programming is PPOLOG
(Programming logic)
Example: in JavaScript
constsum = a =>b =>a + b;
console.log (sum (5) (3)); // 8
Structural Programming
Procedural Programming
Object-Oriented Programming
I. Eliminate redundancy.
V. Provide extensibility.
I. Size- Object oriented programs are much larger than other programs.
II. Slow Speed – Due to large size of the programs its execution speed becomes slow.
III. Many skills – A programmer required many skills for a better programming. Different skills like
programming skills, designing skills, logical thinking and problem-solving skills are needed..
IV. Complex Design – Designing and proper implementation of Object Oriented Programming
(OOP) concepts is complex and burdensome.
OOP POP
It is the most recent programming concept which uses the It is the old programming concept that uses the top-
bottom-up approach. down approach.
Programs are divided into a number of entities called object. Programs are divided into a number of functions.
Emphasis is on data rather than on procedures. Emphasis is on procedures rather than on data.
It does not allow data to move freely around the program It allows data to move freely around the program
from one object to another object. from one function to another function.
Data is hidden inside the object and cannot be accessed by Data is open and can be freely accessed by all the
external functions. programs.
Problem is viewed as a real world entity. Problem is not viewed as a real world entity
OOP is written by using HLL such as C++, Java, ASP.Net etc. POP is written by using HLL/MLL such as C,
FORTRAN etc.
The principles of OOPs are:
Class- Class is a blueprint for an object. A class is the user defined data type with a template that
serves to define its properties. A class can have any number of properties and methods to access
the value of various kinds of methods. A class is a collection or group of similar objects that have
same properties, common behavior and relationships. Each class describes a set of individual
objects.
Object-
- An object is any entity, things or organization that exits in real world. It consists of two
fundamental characteristics: its attributes and behaviors.
- Objects are the basic run time entities in an object oriented system.
- They represent any item that the program can handle.
- When a program is executed, the objects interact by sending messages to one another.
- Eg: Consider an object ‘Student’ with data (name, roll, mark) and function total(), average(),
display().
Encapsulation- The Encapsulation is the mechanism of combining data function together into a
single unit.
- It prevents the data being accessed by other code.
Abstraction- Abstraction is the act of representing the essential features without including the
background details or explanations.
- Classes are the concept of abstraction. So, class is an abstract data type.
- It can manage the program complexity.
Advantages of Data Abstraction:
Inheritance- Inheritance is the capability of one class to acquire properties and characteristics from
another class. The class whose properties are inherited by other class is called the parent or base or
super class. And, the class which inherits properties of other class is called Child or Derived or Sub
Class.
Purpose of inheritance
1. Code reusability
2. Method overriding
3. Use of virtual function
Advantages of Inheritance
1. Reusability
2. Saves time and effort
3. Extendibility of the code
Aminal
Class Dog inherits properties from
its super class Animal
Dog
Types of inheritance
1. Single Inheritance
When a single class is being inherited by a class, it is called single or simple inheritance. In other word, a
derived class with only one base class is called single inheritance.
B
2. Multi Level inheritance
Class B
Class C
Hierarchical Inheritance is the process of deriving two or more classes from single base class.
Class A
4. Multiple Inheritance
Multiple inheritances are a type of inheritance in which new class is created from more than one
base class.
A B
Polymorphism- Polymorphism means “having many forms”. The polymorphism allows different
object to respond to the same message in different ways, the response specific to the type of
object. It is important when object oriented programs dynamically creating and destroying the
objects in runtime. Example of Polymorphism in oop:
1)operator overloading
2)function overloading etc.
There are two types of polymorphism:
1)Runtime polymorphism
2)Compile time polymorphism
Example:
Different between OOP and POP
OOP POP
It is the most recent programming concept which uses the It is the old programming concept that uses the top-
bottom-up approach. down approach.
Programs are divided into a number of entities called object. Programs are divided into a number of functions.
Emphasis is on data rather than on procedures. Emphasis is on procedures rather than on data.
It does not allow data to move freely around the program It allows data to move freely around the program
from one object to another object. from one function to another function.
Data is hidden inside the object and cannot be accessed by Data is open and can be freely accessed by all the
external functions. programs.
Problem is viewed as a real world entity. Problem is not viewed as a real world entity
OOP is written by using HLL such as C++, Java, ASP.Net etc. POP is written by using HLL/MLL such as C,
FORTRAN etc.
2. ……… is a concept or thing with defined boundaries that are relevant to the problem we are dealing
with
3. ……. is a collection or group of similar objects that have the same properties, common behavior and
relationships.
a. Object b. Class c. Constant d. None of the above
4. ………. is a property that allows the reuse of an existing class to build a new class.
5. …. is the process that allows selective hiding of data and functions in a class.
7. …. Is the process of identifying properties and methods related to a particular entity as relevant to the
application?
8. Under …. Inheritance, there is a derived class with only one base class.
a. procedural paradigm b. Structural paradigm c. Object Oriented paradigm d. None of the above
10. …… is a programming paradigm based upon the concept of procedure calls, in which statements are
structured into procedures?