# -*- coding: gbk -*-
# -*- coding: utf-8 -*-
"""
@author: Edgar
这是门面模式的一个应用场景。(具体故事情节请见《设计模式之禅》)
·门面模式把一套方法封装起来,用户不需要知道具体的实现细节。
"""
class LetterProcessImpl(object):
def writeContext(self, context):
print '填写信的内容...' + context
def fillEnvelope(self, address):
print '邮寄地址为:' + address
def letterIntoEnvelope(self):
print '把信放到信封中。'
def sendLetter(self):
print '邮递信件。'
class ModenPostOffice(object):
def __init__(self):
self.LetterImpl = LetterProcessImpl()
self.Police = Police()
def sendLetter(self, context, address):
self.LetterImpl.writeContext(context)
self.LetterImpl.fillEnvelope(address)
self.LetterImpl.letterIntoEnvelope()
self.Police.check()
self.LetterImpl.sendLetter()
class Police(object):
def check(letter):
print '检查通过。'
if __name__ == '__main__':
hellRoadPostOffice = ModenPostOffice()
hellRoadPostOffice.sendLetter('Hello World', '天堂路')
设计模式之门面模式
最新推荐文章于 2023-09-14 08:58:15 发布