精通Python设计模式 高清完整.pdf版+源码 下载
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 2209 2016-03-18 18:41 mpdp-code-masterchapter1abstract_factory.py
....... 2895 2016-03-18 18:41 mpdp-code-masterchapter1datadonut.json
....... 1464 2016-03-18 18:41 mpdp-code-masterchapter1dataperson.xml
....... 1952 2016-03-18 18:41 mpdp-code-masterchapter1factory_method.py
....... 121 2016-03-18 18:41 mpdp-code-masterchapter1id.py
....... 1398 2016-03-18 18:41 mpdp-code-masterchapter10chain.py
....... 1778 2016-03-18 18:41 mpdp-code-masterchapter11command.py
....... 1671 2016-03-18 18:41 mpdp-code-masterchapter11first-class.py
....... 4723 2016-03-18 18:41 mpdp-code-masterchapter12interpreter.py
....... 1954 2016-03-18 18:41 mpdp-code-masterchapter13observer.py
....... 2733 2016-03-18 18:41 mpdp-code-masterchapter14state.py
....... 524 2016-03-18 18:41 mpdp-code-masterchapter15langs.py
....... 1439 2016-03-18 18:41 mpdp-code-masterchapter15strategy.py
....... 1925 2016-03-18 18:41 mpdp-code-masterchapter16graph.py
....... 1689 2016-03-18 18:41 mpdp-code-masterchapter16graph_template.py
....... 1847 2016-03-18 18:41 mpdp-code-masterchapter16graph_template_slower.py
....... 570 2016-03-18 18:41 mpdp-code-masterchapter16 emplate.py
....... 831 2016-03-18 18:41 mpdp-code-masterchapter2apple-factory.py
....... 4485 2016-03-18 18:41 mpdp-code-masterchapter2uilder.py
....... 871 2016-03-18 18:41 mpdp-code-masterchapter2uilder2.py
....... 1420 2016-03-18 18:41 mpdp-code-masterchapter2computer-builder.py
....... 396 2016-03-18 18:41 mpdp-code-masterchapter3clone.py
....... 1829 2016-03-18 18:41 mpdp-code-masterchapter3prototype.py
....... 775 2016-03-18 18:41 mpdp-code-masterchapter4adapter.py
....... 414 2016-03-18 18:41 mpdp-code-masterchapter4external.py
....... 1096 2016-03-18 18:41 mpdp-code-masterchapter5mymath.py
....... 2600 2016-03-18 18:41 mpdp-code-masterchapter6facade.py
....... 1789 2016-03-18 18:41 mpdp-code-masterchapter7flyweight.py
....... 1371 2016-03-18 18:41 mpdp-code-masterchapter8mvc.py
....... 993 2016-03-18 18:41 mpdp-code-masterchapter9lazy.py
............此处省略23个文件信息
class Frog:
def __init__(self name):
self.name = name
def __str__(self):
return self.name
def interact_with(self obstacle):
print(‘{} the Frog encounters {} and {}!‘.format(self
obstacle obstacle.action()))
class Bug:
def __str__(self):
return ‘a bug‘
def action(self):
return ‘eats it‘
class FrogWorld:
def __init__(self name):
print(self)
self.player_name = name
def __str__(self):
return ‘
------ Frog World ———‘
def make_character(self):
return Frog(self.player_name)
def make_obstacle(self):
return Bug()
class Wizard:
def __init__(self name):
self.name = name
def __str__(self):
return self.name
def interact_with(self obstacle):
print(‘{} the Wizard battles against {} and {}!‘.format(self obstacle obstacle.action()))
class Ork:
def __str__(self):
return ‘an evil ork‘
def action(self):
return ‘kills it‘
class WizardWorld:
def __init__(self name):
print(self)
self.player_name = name
def __str__(self):
return ‘
------ Wizard World ———‘
def make_character(self):
return Wizard(self.player_name)
def make_obstacle(self):
return Ork()
class GameEnvironment:
def __init__(self factory):
self.hero = factory.make_character()
self.obstacle = factory.make_obstacle()
def play(self):
self.hero.interact_with(self.obstacle)
def validate_age(name):
try:
age = input(‘Welcome {}. How old are you? ‘.format(name))
age = int(age)
except ValueError as err:
print(“Age {} is invalid please try
again…“.format(age))
return (False age)
return (True age)
def main():
name = input(“Hello. What‘s your name? “)
valid_input = False
while not valid_input:
valid_input age = validate_age(name)
game = FrogWorld if age < 18 else WizardWorld
environment = GameEnvironment(game(name))
environment.play()
if __name__ == ‘__main__‘:
main()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 2209 2016-03-18 18:41 mpdp-code-masterchapter1abstract_factory.py
....... 2895 2016-03-18 18:41 mpdp-code-masterchapter1datadonut.json
....... 1464 2016-03-18 18:41 mpdp-code-masterchapter1dataperson.xm
....... 1952 2016-03-18 18:41 mpdp-code-masterchapter1factory_method.py
....... 121 2016-03-18 18:41 mpdp-code-masterchapter1id.py
....... 1398 2016-03-18 18:41 mpdp-code-masterchapter10chain.py
....... 1778 2016-03-18 18:41 mpdp-code-masterchapter11command.py
....... 1671 2016-03-18 18:41 mpdp-code-masterchapter11first-class.py
....... 4723 2016-03-18 18:41 mpdp-code-masterchapter12interpreter.py
....... 1954 2016-03-18 18:41 mpdp-code-masterchapter13observer.py
....... 2733 2016-03-18 18:41 mpdp-code-masterchapter14state.py
....... 524 2016-03-18 18:41 mpdp-code-masterchapter15langs.py
....... 1439 2016-03-18 18:41 mpdp-code-masterchapter15strategy.py
....... 1925 2016-03-18 18:41 mpdp-code-masterchapter16graph.py
....... 1689 2016-03-18 18:41 mpdp-code-masterchapter16graph_template.py
....... 1847 2016-03-18 18:41 mpdp-code-masterchapter16graph_template_slower.py
....... 570 2016-03-18 18:41 mpdp-code-masterchapter16 emplate.py
....... 831 2016-03-18 18:41 mpdp-code-masterchapter2apple-factory.py
....... 4485 2016-03-18 18:41 mpdp-code-masterchapter2uilder.py
....... 871 2016-03-18 18:41 mpdp-code-masterchapter2uilder2.py
....... 1420 2016-03-18 18:41 mpdp-code-masterchapter2computer-builder.py
....... 396 2016-03-18 18:41 mpdp-code-masterchapter3clone.py
....... 1829 2016-03-18 18:41 mpdp-code-masterchapter3prototype.py
....... 775 2016-03-18 18:41 mpdp-code-masterchapter4adapter.py
....... 414 2016-03-18 18:41 mpdp-code-masterchapter4external.py
....... 1096 2016-03-18 18:41 mpdp-code-masterchapter5mymath.py
....... 2600 2016-03-18 18:41 mpdp-code-masterchapter6facade.py
....... 1789 2016-03-18 18:41 mpdp-code-masterchapter7flyweight.py
....... 1371 2016-03-18 18:41 mpdp-code-masterchapter8mvc.py
....... 993 2016-03-18 18:41 mpdp-code-masterchapter9lazy.py
............此处省略23个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)