外觀模式(Facade):為子系統中的一組接口提供一個一致的界面,此模板定義了一個高層接口,這個接口使得這一子系統更加容易使用。
namespace Facade { public class SubSystemOne { public void MethodeOne() { Console.WriteLine("子系統方法一"); } } public class SubSystemTwo { public void MethodeTwo() { Console.WriteLine("子系統方法二"); } } public class SubSystemThree { public void MethodeThree() { Console.WriteLine("子系統方法三"); } } public class SubSystemFour { public void MethodeFour() { Console.WriteLine("子系統方法四"); } } public class Facade { SubSystemOne one; SubSystemTwo two; SubSystemThree three; SubSystemFour four; public Facade() { one = new SubSystemOne(); two = new SubSystemTwo(); three = new SubSystemThree(); four=new SubSystemFour(); } public void MethodA() { Console.WriteLine("\n方法組A() ---"); one.MethodeOne(); two.MethodeTwo(); four.MethodeFour(); } public void MethodB() { Console.WriteLine("\n方法組B() ---"); two.MethodeTwo(); three.MethodeThree(); } } }View Code
測試代碼:
Facade.Facade facade = new Facade.Facade(); facade.MethodA(); facade.MethodB();View Code