By The Department of
Computer Science & Engineering
Patel college of science and technology
Submitted By :--
• Vinit Singh Pathir
• Anshu Prajapat
Submitted To :--
Mr.Vikas Kalme Sir
Session 2023-24
Topic
 Introduction
 What is Encapsulation?
 Real Life example of
Encapsulation
 Advantages of Encapsulations
 Important to know
 Example of Encapsulation in
C++
 Types Of Encapsulation
 Why we use Encapsulation?
Introduction to
Encapsulation
Introduction
Encapsulation means binding
(joining) a variables (data)
with a function (Methods).
Introduction
Encapsulation means binding
(joining) a variables (data)
with a function (Methods).
E.g. When we encapsulate a
class
Introduction
Encapsulation means binding
(joining) a variables (data)
with a function (Methods).
 It keep the important but
unnecessary data away
from the user of the
program
E.g. When we encapsulate a
class
Encapsulation in C++
Encapsulation in C++ is defined as
the wrapping up of data and
information in a single unit.
What is Encapsulation in C++?
In Object Oriented Programming
(OOP),
Encapsulation is defined as binding
together the data and the functions
that manipulate them.
Real life example of
Encapsulation
Real Life Practical example of Encapsulation
As we know ,in a company, there are different sections like the accounts
section, finance section, sales section, etc.
The finance section handles all the financial transactions and keeps
records of all the data related to finance.
Similarly, the sales section handles all the sales-related activities and
keeps records of all the sales.
Now there may arise a situation when for some reason an official from
the finance section needs all the data about sales in a particular month.
In this case, he is not allowed to directly access the data of the sales
section. He will first have to contact some other officer in the sales section
and then request him to give the particular data.
This is what encapsulation means our computer programming
Why we need to
use
Encapsulation ?
Why we need to use Encapsulation ?
Encapsulation is a way to restrict the direct access
to some components of an object, so users cannot
access state values for all of the variables of a
particular object.
Encapsulation can be used to hide both data members
and data functions or methods associated with an
instantiated class or object.
The primary purpose of encapsulation is to hide an
object’s internal representation or state from the
outside. This concept is also known as information
hiding.
Advantages
Of
Encapsulate
Advantages of Encapsulations
Data Hiding : Restricts access to data
members, hiding
implementation details.
Control : Provides better control over class
attributes and methods.
Security: Increases security of data.
Flexibility: Allows changes to one part of
the code without
affecting
others.
Reusability: By defining one class, we can
create many objects
with consistent
behavior.
Types
Of
Encapsulate
Types Of Encapsulation
• There are three basic types Encapsulation
 Member variable encapsulation,
 Function encapsulation and
 Class encapsulation
Encapsulation
Member
variable
encapsulati
-on
Function
encapsulati
-on
Class
encapsulati
-on
Member Variable
Encapsulation
Member Variable Encapsulation:
 In this type, data
members (also
known as
attributes or
fields) are
encapsulated
within a class.
Member Variable Encapsulation:
 Data members
are typically
private by
default, ensuring
that they are not
directly
accessible from
outside the class.
 In this type, data
members (also
known as
attributes or
fields) are
encapsulated
within a class.
Member Variable Encapsulation:
 Data members
are typically
private by
default, ensuring
that they are not
directly
accessible from
outside the class.
 To access these
data members,
we use setter and
getter methods
(also known as
mutator and
accessor
methods).
 In this type, data
members (also
known as
attributes or
fields) are
encapsulated
within a class.
Function
Encapsulation
Function Encapsulation:
 Function
encapsulation
refers to
marking a
method of code
as private to
prevent
unauthorized
access.
Function Encapsulation:
 Function
encapsulation
refers to
marking a
method of code
as private to
prevent
unauthorized
access.
 These private
methods are
hidden from
external code.
Function Encapsulation:
 Function
encapsulation
refers to
marking a
method of code
as private to
prevent
unauthorized
access.
 These private
methods are
hidden from
external code.
 It ensures that
only
authorized
parts of the
code can call
specific
functions.
Class
Encapsulation
 Class Encapsulation:
 Class
encapsulation
involves
declaring an
entire class as
private to
restrict user
access.
 Class Encapsulation:
 Class
encapsulation
involves
declaring an
entire class as
private to
restrict user
access.
 This means
that other
classes cannot
directly
interact with
the
encapsulated
class.
 Class Encapsulation:
 Class
encapsulation
involves
declaring an
entire class as
private to
restrict user
access.
 It allows hiding
implementatio
n details and
organizing
related data
and methods
together.
 This means
that other
classes cannot
directly
interact with
the
encapsulated
class.
Example of
Encapsulation in C++
Example of Encapsulation in C++
In this example:
 We calculate the area of a rectangle using the
getArea() method.
 The length and breadth data members are
private, encapsulating them within the
Rectangle class.
 The public interface allows access to the
getArea() method.
Important to know
Encapsulation is counted as one in four main pillar Of
Object Oriented Programming (OOPs)
Additional Notes:
 Getter and setter functions provide
controlled access to class members.
 Encapsulation is not just data hiding;
it’s about bundling related fields and
methods together.
 It improves readability,
maintainability, and security.
Thank
You

Presentation related to Encapsulation and OOPs

  • 1.
    By The Departmentof Computer Science & Engineering Patel college of science and technology Submitted By :-- • Vinit Singh Pathir • Anshu Prajapat Submitted To :-- Mr.Vikas Kalme Sir Session 2023-24
  • 2.
    Topic  Introduction  Whatis Encapsulation?  Real Life example of Encapsulation  Advantages of Encapsulations  Important to know  Example of Encapsulation in C++  Types Of Encapsulation  Why we use Encapsulation?
  • 3.
  • 4.
    Introduction Encapsulation means binding (joining)a variables (data) with a function (Methods).
  • 5.
    Introduction Encapsulation means binding (joining)a variables (data) with a function (Methods). E.g. When we encapsulate a class
  • 6.
    Introduction Encapsulation means binding (joining)a variables (data) with a function (Methods).  It keep the important but unnecessary data away from the user of the program E.g. When we encapsulate a class
  • 7.
  • 8.
    Encapsulation in C++is defined as the wrapping up of data and information in a single unit. What is Encapsulation in C++? In Object Oriented Programming (OOP), Encapsulation is defined as binding together the data and the functions that manipulate them.
  • 9.
    Real life exampleof Encapsulation
  • 10.
    Real Life Practicalexample of Encapsulation As we know ,in a company, there are different sections like the accounts section, finance section, sales section, etc. The finance section handles all the financial transactions and keeps records of all the data related to finance. Similarly, the sales section handles all the sales-related activities and keeps records of all the sales. Now there may arise a situation when for some reason an official from the finance section needs all the data about sales in a particular month. In this case, he is not allowed to directly access the data of the sales section. He will first have to contact some other officer in the sales section and then request him to give the particular data. This is what encapsulation means our computer programming
  • 11.
    Why we needto use Encapsulation ?
  • 12.
    Why we needto use Encapsulation ? Encapsulation is a way to restrict the direct access to some components of an object, so users cannot access state values for all of the variables of a particular object. Encapsulation can be used to hide both data members and data functions or methods associated with an instantiated class or object. The primary purpose of encapsulation is to hide an object’s internal representation or state from the outside. This concept is also known as information hiding.
  • 13.
  • 14.
    Advantages of Encapsulations DataHiding : Restricts access to data members, hiding implementation details. Control : Provides better control over class attributes and methods. Security: Increases security of data. Flexibility: Allows changes to one part of the code without affecting others. Reusability: By defining one class, we can create many objects with consistent behavior.
  • 15.
  • 16.
    Types Of Encapsulation •There are three basic types Encapsulation  Member variable encapsulation,  Function encapsulation and  Class encapsulation Encapsulation Member variable encapsulati -on Function encapsulati -on Class encapsulati -on
  • 17.
  • 18.
    Member Variable Encapsulation: In this type, data members (also known as attributes or fields) are encapsulated within a class.
  • 19.
    Member Variable Encapsulation: Data members are typically private by default, ensuring that they are not directly accessible from outside the class.  In this type, data members (also known as attributes or fields) are encapsulated within a class.
  • 20.
    Member Variable Encapsulation: Data members are typically private by default, ensuring that they are not directly accessible from outside the class.  To access these data members, we use setter and getter methods (also known as mutator and accessor methods).  In this type, data members (also known as attributes or fields) are encapsulated within a class.
  • 21.
  • 22.
    Function Encapsulation:  Function encapsulation refersto marking a method of code as private to prevent unauthorized access.
  • 23.
    Function Encapsulation:  Function encapsulation refersto marking a method of code as private to prevent unauthorized access.  These private methods are hidden from external code.
  • 24.
    Function Encapsulation:  Function encapsulation refersto marking a method of code as private to prevent unauthorized access.  These private methods are hidden from external code.  It ensures that only authorized parts of the code can call specific functions.
  • 25.
  • 26.
     Class Encapsulation: Class encapsulation involves declaring an entire class as private to restrict user access.
  • 27.
     Class Encapsulation: Class encapsulation involves declaring an entire class as private to restrict user access.  This means that other classes cannot directly interact with the encapsulated class.
  • 28.
     Class Encapsulation: Class encapsulation involves declaring an entire class as private to restrict user access.  It allows hiding implementatio n details and organizing related data and methods together.  This means that other classes cannot directly interact with the encapsulated class.
  • 29.
  • 30.
    Example of Encapsulationin C++ In this example:  We calculate the area of a rectangle using the getArea() method.  The length and breadth data members are private, encapsulating them within the Rectangle class.  The public interface allows access to the getArea() method.
  • 31.
  • 32.
    Encapsulation is countedas one in four main pillar Of Object Oriented Programming (OOPs)
  • 33.
    Additional Notes:  Getterand setter functions provide controlled access to class members.  Encapsulation is not just data hiding; it’s about bundling related fields and methods together.  It improves readability, maintainability, and security.
  • 34.