-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncapsulation.py
More file actions
43 lines (35 loc) · 1.44 KB
/
Encapsulation.py
File metadata and controls
43 lines (35 loc) · 1.44 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
# Encapsulation
class order:
def __init__(self, customer_name, items, total, discount):
self.customer_name=customer_name
self.items=items
self.__total=total # Private variable
self.__discount=discount # Private variable
def __calculation(self): # Private Method
return self.__total - self.__discount
def _admin_view(self): # Protected Method
return {
"Customer_Name" : self.customer_name,
"Items" : self.items,
"Total" : self.__total,
"Discount" : self.__discount,
"Final amount" : self.__calculation() # Privated method called by another method
}
def _Customer_view(self): # Protected Method
return {
"Customer_Name" : self.customer_name,
"Items" : self.items,
"Final amount" : self.__calculation()} # private Method
class Admin:
def admin_access(self, Order): # Order is object of class order
return Order._admin_view() # Parent class method
class customer:
def customer_access(self, Order): # Order is object of class order
return Order._Customer_view() # Parent class method
Order=order("sanoop", ["mango","orange","apples"], 590, 79)
admin=Admin()
print("ADMIN VIEW")
print(admin.admin_access(Order))
cus=customer()
print("CUSTOMER VIEW")
print(cus.customer_access(Order))