Tuesday, May 14, 2019

Class relations

Lock classes and relationships

Inheritance

User Class

class User():
    def __init__(self,name, email, securityLevel):
        self.name=name
        self.email=email
        self.securityLevel=securityLevel

    def getName(self):
        return self.name
    
    def getEmail(self):
        return self.email

    def getSecurityLevel(self):
        return self.securityLevel

    def __str__(self):
        return self.name + ", " + self.email

Staff Class

from user import User

class Staff(User):
    def __init__(self, name, email, securityLevel, position):
        self.name=name
        self.email=email
        self.securityLevel=securityLevel
        self.position=position

    def getPosition(self):
        return self.position

    def __str__(self):
        return super(Staff, self).__str__() + ", " + self.position

main

from staff import Staff
def setUser():
    s=Staff('Sue', 's@gmail.com', 'high', 'Janitor')
    print(s.getEmail())
    print(s.getName())
    print(s)

def main():
    setUser()

main()

No comments:

Post a Comment