-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcomp_agg_association.py
70 lines (48 loc) · 1.25 KB
/
comp_agg_association.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#Association
class A():
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
def addNums(self):
self.b + self.c
class B():
def __init__(self, d, e):
self.d = d
self.e = e
def addAllNums(self, Ab, Ac):
x = self.d + self.e + Ab + Ac
return x
ting = A("yo", 2, 6)
ling = B(5, 9)
print(ling.addAllNums(ting.b, ting.c))
#Composition
class Salary:
def __init__(self, pay):
self.pay = pay
def get_total(self):
return (self.pay * 12)
class Employee:
def __init__(self, pay, bonus):
self.pay = pay
self.bonus = bonus
self.obj_salary = Salary(self.pay)
def annual_salary(self):
return "Total: " + str(self.obj_salary.get_total()+self.bonus)
obj_emp = Employee(100, 10)
print(obj_emp.annual_salary())
#Aggregation
class Salary:
def __init__(self, pay):
self.pay = pay
def get_total(self):
return self.pay * 12
class Employee:
def __init__(self, pay, bonus):
self.pay = pay
self.bonus = bonus
def annual_salary(self):
return "Total: " + str(self.pay.get_total() + self.bonus)
obj_sal = Salary(100)
obj_emp = Employee(obj_sal, 10)
print(obj_emp.annual_salary())