Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User:
- """
- Basic User class, keeps name and age which is common for all users
- """
- name = "User"
- age = 0
- class Privilege:
- """
- To represent privilege object
- Only holds type and name of the object
- """
- def __init__(self, p_type, p_name):
- self.p_type = p_type
- self.p_name = p_name
- def __repr__(self):
- return "Type: {}, name: {}".format(self.p_type, self.p_name)
- class Admin(User):
- """
- Admin class inherits from basic User class taking the name and age fields from its parent
- In case we don't provide those two buddies, default values will be used (User and 0)
- """
- def __init__(self, privileges, name=None, age=None):
- if name:
- self.name = name
- if age:
- self.age = age
- self.privileges = privileges
- def show_privileges(self):
- print(self.privileges)
- def show_info(self):
- print("{}: age={}".format(self.name, self.age))
- admin = Admin([Privilege(0, "write"), Privilege(1, "read")])
- admin.show_privileges()
- admin.show_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement