-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolymorphism.py
50 lines (31 loc) · 944 Bytes
/
polymorphism.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
class User:
def __init__(self, email):
self.email = email
def singIn(self):
print('logged in!!!')
def attack(self):
print(f'do nothing!!!')
class Wizard(User):
def __init__(self, name, power, email):
super().__init__(email)
self.name = name
self.power = power
def attack(self):
User.attack(self)
print(f'attacked with power of {self.power}')
pass
class Archer(User):
def __init__(self, name, num_arrows, email):
super().__init__(email)
self.name = name
self.num_arrows = num_arrows
def attack(self):
print(f'attacked with arrows left {self.num_arrows}')
pass
wizard1 = Wizard('Merlin', 50, 'email')
archer1 = Archer('Robin', 500, 'email')
# introspection - ability to determine object type at run time
print(dir(wizard1))
print(wizard1.email)
for char in [wizard1, archer1]:
char.attack()