设计模式:外观模式
外观模式(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(); } } }
测试代码:
Facade.Facade facade = new Facade.Facade(); facade.MethodA(); facade.MethodB();