-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4pillar.py
More file actions
114 lines (85 loc) · 3.37 KB
/
4pillar.py
File metadata and controls
114 lines (85 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# # Pillars - OOP
''' 1. Abstraction
2. Encapsulation
3. Inheritence
4. polymorphism
'''
# # ABSTRACTION
'''
--> Abstraction hides the complex inner working of an object,
exposing only the essenital parts for interaction.
--> Real-worldExample : Think about driving a car. You Use the steering, wheel and pedals to
control the car, without needing to know the engine mechanics or
braking systems.
'''
# class car:
# def start_engine(self):
# print("Engine started")
# def accelerate(self):
# print("car accelerating")
# def brake(self):
# print("car Stopping")
# car = car()
# car.start_engine()
# car.accelerate()
# car.brake()
# # Encapsulation
''' --> Encapsulation involves wrapping data and methods that operates on that data within one unit, such as class.
This protects the data from external interference and misuse, improving security and maintainability.
--> Real-world Example : Imagine an ATM machine - you interact with a limited interface
(e.g., withdraw,deposit, check balance) but do not have access
to the inner mechanics or backend functions
'''
# class ATM:
# def __init__(self,balance):
# self.__balance = balance # Private attribute
# def deposit(self,amount):
# self.__balance += amount
# print(f" Deposited {amount}. new balance:{self.__balance}")
# def withdraw(self,amount):
# if amount <= self.__balance:
# self.__balance -= amount
# print(f" withdraw { amount}. new balance: { self.__balance}")
# else:
# print("Insfficient balance")
# atm = ATM(1000)
# atm.deposit(500)
# atm.withdraw(300)
# class Database:
# def __init__(self):
# # self.storage = {} # Public attribute
# # self._storage = {} # protected
# self.__storage = {} # private
# def write(self,key,value):
# self.__storage[key] = value
# def read(self,key):
# if key in self.__storage:
# print(self.__storage[key])
# else:
# print("Key is not found in database")
# db = Database()
# db.write("Hemi",23)
# db.read("Hemi")
# db.write("name","hello")
# # print(db.storage)
# db.read("name")
# # Encapsulation : restricting direct access to some data and methods to prevent accidental modification.
# class BankAccount:
# def __init__(self,Account_number,balance):
# self.__Account_number = Account_number
# self.__balance = balance
# def check_balance(self):
# print(f"the balance is {self.__balance}")
# def deposit(self,amount):
# self.__balance += amount
# print(f"The Deposited ammount is {amount} new balance is {self.__balance}")
# def withdraw_funds(self,amount):
# if amount <= self.__balance:
# self.__balance -= amount
# print(f" The balance after withdraw {amount} the avilable balance is {self.__balance}")
# else:
# print("Insufficent balance")
# account = BankAccount("1234",1000)
# account.check_balance()
# account.deposit(500)
# # account.__balance() # o/p : "BankAccount" object has no attribute '__balance'.