class EtherNet { public void Send(string data) { Console.WriteLine("EtherNet is Sending: {0}",data); } } class EtherNetAdaptor :EtherNet, Device { public void Transform(string data) { base.Send(data); } } class COM : Device { public void Transform(string data) { Console.WriteLine("COM is Transforming :{0}", data); } } class USB : Device { public void Transform(string data) { Console.WriteLine("USB is Transforming :{0}", data); } } interface Device { void Transform(string data); } class Computer { [STAThread] static void Main(string[] args) { Console.WriteLine(" 请输入设备类型:"); string deviceType = Console.ReadLine().ToLower(); Console.WriteLine(" 请输入要发送的数据:"); string data = Console.ReadLine().ToLower(); Device device = null; switch (deviceType) { case "net": device = new EtherNetAdaptor(); break; case "com": device = new COM(); break; case "usb": device = new USB(); break; default: Console.WriteLine(" 对不起,没有此种设备!!"); break; } device.Transform(data); } } |