Advertisement
rangga_hrdme

ENCAPSULATION

Apr 7th, 2021 (edited)
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. class Human(object): # MAIN CLASS
  2.     name = None
  3.  
  4.     def __init__(self, name): # Function of properties
  5.         self.name = name
  6.  
  7.     def play(self):
  8.         print("{} play mobile game".format(self.name)) # Function of method
  9.  
  10. class Human_Now(Human):
  11.     email = None # To be public
  12.     __password = None # To be private (ENCAPSULATION)
  13.  
  14.     def set_email(self, email): # Public
  15.         self.email = email
  16.  
  17.     def set_password(self, password): # Public
  18.         self.__password = password
  19.         self.__hide_password()
  20.  
  21.     def __hide_password(self): # To be private (ENCAPSULATION)
  22.         self.__password = self.__password.replace("e", "*")
  23.  
  24.     def info(self): # Public
  25.         print("name ={}, email ={}, password ={}".format(self.name, self.email, self.__password))
  26.  
  27. programmer = Human_Now("rangga")
  28. programmer.set_email("rangga@google.com")
  29. programmer.set_password("VerySecret")
  30. programmer.info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement