0% found this document useful (0 votes)
13 views14 pages

Encapsulation

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 14

ENCAPSULATION

By K.Sabarimukunthan
INDEX
1. What is Encapsulation?
2. How Does It Work?
3. Key Features
4. The Superpowers Of Encapsulation
5. Real Life Analogy
6. Advantages and Disadvantages
7. Implementation in Programming
8. Encapsulation vs Abstraction
9. Access Modifiers
10.Why Encapsulation Matters
What is Encapsulation?

● Definition: Encapsulation is the process of bundling data and


methods that operate on the data within one unit, usually a class.

● Core Idea: Restrict direct access to some parts of an object


while exposing only necessary parts.

● Visual Prompt: Picture of a capsule (symbolizing protection).


How Does It Work?

Encapsulation uses access specifiers to control access:

● Private: Hidden from outside.

● Protected: Visible to subclasses.

● Public: Open for all.


Key Features:

1. Combines data (fields) and methods (functions) into a single unit


(class).
2. Access modifiers like private, protected, and public control access
to class members.
3. Promotes data hiding and protects the internal state of the
object.
The Superpowers Of Encapsulation

1. Data Security: Protects sensitive information.


2. Code Modularity: Breaks down problems into manageable
units.

3. Improved Maintenance: Easier debugging and updates.


4. Reusability: Write once, use many times.
Real Life Analogy:

Example: A bank account:


● Data (balance) is private.
● Methods (deposit, withdraw) are public.
● Users can't directly modify the balance but use methods to do so.

Why Encapsulation?
● To protect sensitive data and ensure operations follow rules
Advantages and Disadvantages

Advantages: Disadvantages:
● Increases code security. ● May increase code
● Enhances system complexity.
robustness. ● Could require more memory
● Makes debugging easier. and resources.
Implementation in Programming

public class BankAccount {

private double balance;

public BankAccount(double initialBalance) {

balance = initialBalance;

public void deposit(double amount) {


Implementation in Programming
if (amount > 0) {

balance += amount;

public double getBalance() {

return balance;

}
Encapsulation vs Abstraction
Access Modifiers
Why Encapsulation Matters

In Software Development: Protects systems like banking,


healthcare, and e-commerce.

In Team Collaboration: Enables clear boundaries between


different team modules.

In Future Proofing: Makes systems adaptable to changes.


Thanks!

You might also like