在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 适配器 { class Program { static void Main(string[] args) { Dog dog = new DogAdapter(new Robot()); } public abstract class Dog { public abstract void barking(); public abstract void running(); } public class CommonDog : Dog { public override void barking() { Console.WriteLine("狗叫"); } public override void running() { Console.WriteLine("狗跑"); } } public class DogAdapter : Dog { public DogAdapter(Robot robot) { robot.move(); robot.barking(); } private Robot robot; public Robot Robot { get { return robot; } set { robot = value; } } public override void running() { robot.barking(); } public override void barking() { robot.move(); } } public class Robot { public void barking() { Console.WriteLine("执行机器人叫的方法!"); } public void move() { Console.WriteLine("执行机器人移动的方法!"); } } } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论