-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
56 lines (38 loc) · 928 Bytes
/
build.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
#!/usr/bin/env python
"""
构建模式
"""
class Dog:
def __init__(self, name):
self.name = name
def create_head(self):
print("create_dog_head")
def create_tail(self):
print("create_dog_tail")
def cry(self):
print("wang")
class Cat:
def __init__(self, name):
self.name = name
def create_head(self):
print("create_cat_head")
def create_tail(self):
print("create_cat_tail")
def cry(self):
print("miao")
class Build:
def __init__(self, animal):
self.animal = animal
def create_animal(self):
self.animal.create_head()
self.animal.create_tail()
return self.animal
if __name__ == "__main__":
dogA = Dog("dog_a")
catA = Cat("cat_a")
build = Build(dogA)
dog = build.create_animal()
dog.cry()
build = Build(catA)
cat = build.create_animal()
cat.cry()