c#设计模式之外观模式

  • Post author:
  • Post category:其他


别有洞天 。外观模式使⽤⼀个类作为外观去接触客户,内部管理各个⼦系统。

class Program
{
 static void Main(string[] args)
 {
 Facade facade = new Facade();
 facade.MethodA();
 facade.MethodB();
 Console.Read();
 }
}
class SubSystemOne
{
 public void MethodOne()
 {
 Console.WriteLine(" ⼦系统⽅法⼀");
 }
}
class SubSystemTwo
{
 public void MethodTwo()
 {
 Console.WriteLine(" ⼦系统⽅法⼆");
 }
}
class SubSystemThree
{
 public void MethodThree()
 {
 Console.WriteLine(" ⼦系统⽅法三");
 }
}
class SubSystemFour
{
 public void MethodFour()
 {
 Console.WriteLine(" ⼦系统⽅法四");
 }
}
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.MethodOne();
 two.MethodTwo();
 four.MethodFour();
 }
 public void MethodB()
 {
 Console.WriteLine("\n⽅法组B() ---- ");
 two.MethodTwo();
 three.MethodThree();
 }
}



版权声明:本文为m0_51355586原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。