public void Run() { Console.WriteLine("05.[ 适配器 ].Adapter. 常见应用:旧系统改造、FileStream Stream之类的个转换使用"); // 原本功能 var adaptee = new Adaptee(); adaptee.Star(); System.Console.WriteLine("不推荐使用继承的方式,最好使用传入参数的方式"); // 适配功能更 ITarget target = new Adapter(adaptee); target.HandleStar(); Console.WriteLine("============================================"); }
static void Main(string[] args) { SchoolMaster schoolmaster = new SchoolMaster(); Teacher T1 = new Teacher("陈老师", schoolmaster); Teacher T2 = new Teacher("李老师", schoolmaster); Student S1 = new Student("小赵", schoolmaster); schoolmaster.Criticized(); Adaptee adaptee = new Adaptee(); Adaptera adapters = new Adaptera(); adapters.GetAdaptee(adaptee); adapters.VoltageChange(); Console.ReadKey(); }
public Adapter(Adaptee adaptee) { System.Console.WriteLine("我自己处理了点东西"); _adaptee = adaptee; }