Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Created September 17, 2018 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pknowledge/81ef5bb368b62395e538e43ea367da03 to your computer and use it in GitHub Desktop.
Save pknowledge/81ef5bb368b62395e538e43ea367da03 to your computer and use it in GitHub Desktop.
Python Composition Example
class Salary:
def __init__(self, pay, bonus):
self.pay=pay
self.bonus=bonus
def annual_salary(self):
return (self.pay*12) + self.bonus
class Employee:
def __init__(self, name, age, pay, bonus):
self.name=name
self.age=age
self.obj_salary=Salary(pay, bonus)
def total_salary(self):
return self.obj_salary.annual_salary()
emp = Employee('max', 25, 15000, 10000)
print(emp.total_salary())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment