-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactory.py
More file actions
34 lines (25 loc) · 749 Bytes
/
factory.py
File metadata and controls
34 lines (25 loc) · 749 Bytes
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
class Hero(object):
def move(self):
return "Move It"
def skillA(self):
raise NotImplementedError()
def skillB(self):
raise NotImplementedError()
@staticmethod
def factory(hero_name):
return {'ZhuangZhou': ZhuangZhou(), 'ZhongWuYan': ZhongWuYan()}[hero_name]
class ZhuangZhou(Hero):
def skillA(self):
return 'skillA of ZhuangZhou'
def skillB(self):
return 'skillB of ZhuangZhou'
class ZhongWuYan(Hero):
def skillA(self):
return 'skillA of ZhongWuYan'
def skillB(self):
return 'skillB of ZhongWuYan'
if __name__ == '__main__':
hero = Hero.factory('ZhuangZhou')
print(hero.skillA())
print(hero.skillB())
print(hero.move())