"""
a complete instance example of OOP in python.

test result:
pqy@sda1:~/.../chapter1$ python person_start.py 
Bob Smith 40000
Smith
44000.0
"""

class Person:
    """
    a general person: data + logic
    """
    def __init__(self, name, age, pay = 0, job = None):
        self.name = name
        self.age = age
        self.pay = pay
        self.job = job

    def lastName(self):
        return self.name.split()[-1]

    def giveRaise(self, percent):
        self.pay *= (1.0 + percent)

    def __str__(self):
        return ('<%s => %s: %s, %s>' %
               (slef.__class__.__name__, self.name, self.job, self.pay))

    class Manager(Person):
        """
        a person with custom raise
        inherits general last name
        """

        def __init__(self, name, age, pay):
            Person.__init__(self, name, age, pay, 'manager')

        def giveRaise(self, percent, bonus = 0.1):
            Person.giveRaise(self, percent + bonus) """by call back avoid redundancy"""


    if __name__ == '__main__':
        bob = Person('Bob Smith',44)
        sue = Person('Sue Jones', 47, 40000, 'hardware')
        tom = Manager(name = 'Tom Doe', age = 50, pay = 50000)
        print(sue, sue.pay, sue.lastName())
        for obj in (bob, sue, tom):
            obj.giveRaise(.10)
            print(obj)
                
        
                
