201802181537->深入浅出设计模式:c#外观模式

xiaoxiao2021-02-28  33

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _009外观模式 {     /*-------------------------------------所有具体实现类-------------------------------------*/     public class SubSystemOne     {         private string Name;         public SubSystemOne(string name)         {             this.Name = name;         }         public void MethodOne()         {             Console.WriteLine(string.Format("{0},方法1...", this.Name));         }         public void MethodTwo()         {             Console.WriteLine(string.Format("{0},方法2...", this.Name));         }     }     public class SubSystemTwo     {         private string Name;         public SubSystemTwo(string name)         {             this.Name = name;         }         public void MethodOne()         {             Console.WriteLine(string.Format("{0},方法1...", this.Name));         }         public void MethodTwo()         {             Console.WriteLine(string.Format("{0},方法2...", this.Name));         }     }     public class SubSystemThree     {         private string Name;         public SubSystemThree(string name)         {             this.Name = name;         }         public void MethodOne()         {             Console.WriteLine(string.Format("{0},方法1...", this.Name));         }         public void MethodTwo()         {             Console.WriteLine(string.Format("{0},方法2...", this.Name));         }     }     /*-------------------------------------所有具体实现类-------------------------------------*/     /*-------------------------------------外观类-------------------------------------*/     public class Facade     {         private SubSystemOne one;         private SubSystemTwo two;         private SubSystemThree three;         public Facade()         {             one = new SubSystemOne("ios");             two = new SubSystemTwo("android");             three = new SubSystemThree("ubantu");         }         public void Method1()         {             one.MethodOne();             two.MethodTwo();             three.MethodTwo();         }         public void Method2()         {             one.MethodTwo();             two.MethodTwo();             three.MethodOne();         }     }     /*-------------------------------------外观类-------------------------------------*/     internal class Program     {         private static void Main(string[] args)         {             Facade fadeca = new Facade();             fadeca.Method1();             Console.WriteLine("----------------------");             fadeca.Method2();             Console.WriteLine("----------------------");             /*              * 外观模式比较像是整合其他类的功能的一个接口类              *              * 优点:整合好功能,只管调用,低耦合              *              */             Console.ReadKey();         }     } }
转载请注明原文地址: https://www.6miu.com/read-2623617.html

最新回复(0)