Object Oriented Programming CS Class XII
Object Oriented Programming CS Class XII
Object Oriented Programming CS Class XII
Procedural Programming
Procedural programming is a programming paradigm that allows you to design your code using a structured approach. It
mainly focuses on a sequence of procedures, routines, or subroutines to perform a specific task or to solve a particular
problem. It follows Top-down approach. In procedural programming, the program is divided into small parts called
functions.
ENCAPSULATION
POLYMORPHISM
INHERITANCE
ABSTRACTION
MODULARITY
Page 1|6
2
#include<iostream>
using namespace std;
class Encapsulation
{
private:
int x; // data hidden from outside world
public:
void set(int a)
{
x =a; // function to set value of variable x
}
int get()
{
return x; // function to return value of variable x
}
};
Page 2|6
2
// driver code
int main()
{
Encapsulation obj;
obj.set(5);
cout<<obj.get();
return 0;
}
OUTPUT: 5
In the above program the variable x is made private. This variable can be accessed and manipulated only using the
functions get() and set() which are present inside the class. Thus we can say that here, the variable x and the functions
get() and set() are binded together which is nothing but encapsulation.
MODULARITY: Modularity is the property of a system that has been decomposed into a set of cohesive
and loosely coupled modules. Modularity is closely tied with encapsulation; think of modularity as a way of mapping
encapsulated abstractions into real, physical modules.
Sub Class: The class that inherits properties from another class is called
Subclass or Derived Class.
Super Class: The class whose properties are inherited by a subclass is called Base Class or Super Class.
POLYMORPHISM: This word is the combination of "poly," which means many + "morphs," which
means forms, which together means many forms. Polymorphism in C++ is when the behavior of the same object or
function is different in different contexts. Let's take a real-world example of the word right can mean different things in a
different context. Polymorphism is the capability for a data to be processed in more than one form.
Page 3|6
2
I was right.
In the above sentence, the word right means "correct".
Please take a right turn. The word right refers to the "right direction" in the above sentence.
Example Of Polymorphism
The main difference between data hiding in C++ and encapsulation is that data hiding focuses on improving data
security within the program, while encapsulation deals with hiding the program’s complexity.
Hidden data must be designated as private only. The data in data encapsulation can be public or private.
Data encapsulation focuses on wrapping (i.e., encapsulating) complex data to offer a simplified perspective to the
users, while data hiding focuses on restricting a program’s data use to ensure data security.
Data encapsulation targets how the data is accessed and how different objects behave. Data hiding focuses on object
member accessibility within a class, and information hiding is the most common encapsulation method. The
programmer conceals the object member's structure and its implementation methods.
Data encapsulation is defined as a sub-process of data hiding, and data hiding is both a process and an overall strategy.
So, all data encapsulation is considered data hiding, but not all data hiding is considered data encapsulation.
Page 4|6
2
ADVANTAGES OF OOP
DISADVANTAGES OF OOP
Steep expectation to learn and adapt: The perspective engaged with object-situated programming may not be
normal for certain individuals, and it can invest in some opportunity to become accustomed to it. It is complex to
make programs in view of the cooperation of articles. A portion of the key programming procedures, like
inheritance and polymorphism, can be tested to appreciate at first.
Bigger program size: Object-arranged programs commonly include more lines of code than procedural projects.
More slow projects: Object-arranged programs are normally slower than procedure-based programs, as they
ordinarily require more guidelines to be executed.
Not appropriate for a wide range of issues: There are issues that loan themselves well to useful programming
style, rationale programming style, or strategy based programming style, and applying object-arranged
programming in those circumstances will not bring about effective projects.
Advantages Disadvantages
We can reuse the code multiple times using class Size is larger than other programs
Inherit the class to subclass for data redundancy It required a lot of effort to create
It is easy to maintain and modify It is slower than other programs
It maintains the security of data It is not suitable for some sorts of problems
Low-cost development It takes time to get used to it.
Page 5|6
2
Page 6|6