設計模式之門面模式

2021-06-26 03:02:53 字數 1086 閱讀 9347

# -*- 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', '天堂路')

設計模式之門面模式

模式定義 為子系統中的一組介面提供乙個統一的高層介面,使子系統更容易使用。該模式通過外觀介面與子系統 互動,而不與具體的子系統中的細節互動。分層結構 mvc web應用中的三層結構 遵循原則 迪公尺特原則 最少知識原則,你不需要知道的你就不要知道,你知道幹什麼?封裝變化部分。適用場合 1 乙個系統複...

設計模式之門面模式

外觀模式定義了乙個高層介面,讓子系統更容易使用 結構性場景 有個 允許使用者用自己的積分來兌換商店內禮物,兌換需要經過校驗積分,支付積分,生成訂單的過程,單對呼叫兌換積分的介面來說不用關心裡面的三個過程,只需關心呼叫兌換積分的介面 新建積分兌換禮物實體類 package com.tangbaobao...

設計模式之門面模式

在許多開源的框架中都充分的利用了設計模式這一概念,struts典型的mvc模式的化身,spring是工廠模式和單例模式的充分體現。在專案開發中,能充分利用設計模式的思想來考慮問題,來解決問題,來通過 去實現。不但可以提高 的質量,對程式的擴充套件,重用帶來很大方便。其實我們專案中用設計模式程式設計就...