Presentation related to Encapsulation and OOPs

vinitsinghthakur46 19 views 34 slides Oct 09, 2024
Slide 1
Slide 1 of 34
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34

About This Presentation

Dedicated Project file of Encapsulation


Slide Content

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 implementation 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