5.2. Inheritance None

5.2.1. Diagram

../../_images/inheritance-usecase-none.png

5.2.2. Code

class User:
    def __init__(self, firstname, lastname):
        self.firstname = firstname
        self.lastname = lastname


class Staff:
    def __init__(self, firstname, lastname):
        self.firstname = firstname
        self.lastname = lastname

    def astuple(self):
        data = vars(self).values()
        return tuple(data)


class Admin:
    def __init__(self, firstname, lastname):
        self.firstname = firstname
        self.lastname = lastname

    def astuple(self):
        data = vars(self).values()
        return tuple(data)

    def asdict(self):
        data = vars(self)
        return dict(data)

5.2.3. Usage

>>> mark = User('Mark', 'Watney')
>>>
>>> mark.astuple()
Traceback (most recent call last):
AttributeError: 'User' object has no attribute 'astuple'
>>>
>>> mark.asdict()
Traceback (most recent call last):
AttributeError: 'User' object has no attribute 'asdict'
>>> rick = Staff('Rick', 'Martinez')
>>>
>>> rick.astuple()
('Rick', 'Martinez')
>>>
>>> rick.asdict()
Traceback (most recent call last):
AttributeError: 'Staff' object has no attribute 'asdict'
>>> melissa = Admin('Melissa', 'Lewis')
>>>
>>> melissa.astuple()
('Melissa', 'Lewis')
>>>
>>> melissa.asdict()
{'firstname': 'Melissa', 'lastname': 'Lewis'}