"""
外觀(Facade)模式:為子系統(tǒng)中的一組接口提供一個一致的界面。
——此模式定義了一個高層接口,這個接口使得這一子系統(tǒng)更加容易使用。
與其它模式的區(qū)別:與?“簡單工廠模式+策略模式”的組合版?很類似,不過外觀類的接口不是簡單的調(diào)用功能類的相應(yīng)接口,
而是封裝成了新的接口。
使用場景:維護一個遺留的大型系統(tǒng)是,可能這個系統(tǒng)已經(jīng)非常難以維護和擴展,但是它包含很重要的功能,新的開發(fā)必須依賴于它,
這樣增加外觀Facade類,為系統(tǒng)封裝一個比較清晰簡單的接口,讓新系統(tǒng)與Facade對象交互,F(xiàn)acade與遺留代碼交互所有復雜的工作
"""
import?time
SLEEP?=?0.5
#?復雜部分
class?TC1:
????def?run(self):
????????print("######?測試1?######")
????????time.sleep(SLEEP)
????????print("?設(shè)置...")
????????time.sleep(SLEEP)
????????print("運行測試...")
????????time.sleep(SLEEP)
????????print("拆除...")
????????time.sleep(SLEEP)
????????print("測試結(jié)束了\n")
class?TC2:
????def?run(self):
????????print("######?測試2?######")
????????time.sleep(SLEEP)
????????print("設(shè)置...")
????????time.sleep(SLEEP)
????????print("運行測試...")
????????time.sleep(SLEEP)
????????print("拆除...")
????????time.sleep(SLEEP)
????????print("測試結(jié)束了\n")
class?TC3:
????def?run(self):
????????print("######?測試3?######")
????????time.sleep(SLEEP)
????????print("?設(shè)置...")
????????time.sleep(SLEEP)
????????print("運行測試...")
????????time.sleep(SLEEP)
????????print("拆除...")
????????time.sleep(SLEEP)
????????print("測試結(jié)束了\n")
#?外觀模式
class?ExecuteRunner:
????def?__init__(self):
????????self.tc1?=?TC1()
????????self.tc2?=?TC2()
????????self.tc3?=?TC3()
????????"""列表解析
??????????在一個序列的值上應(yīng)用一個任意表達式,將其結(jié)果收集到一個新的列表中并返回。
??????????它的基本形式是一個方括號里面包含一個for語句對一個iterable對象迭代"""
????????self.tests?=?[i?for?i?in?(self.tc1,?self.tc2,?self.tc3)]
????def?runAll(self):
????????[i.run()?for?i?in?self.tests]
#主程序
if?__name__?==?'__main__':
????testrunner?=?ExecuteRunner()
????testrunner.runAll()