windows系统
vs个版本开发工具
新建一个控制台应用程序,命名为门面模式,如下图所示:
新建一个相机类Camera类,添加相应方法,如下图所示:public class Camera { public void TurnOn() { Console.WriteLine('turning on the camera.'); } public void TurnOff() { Console.WriteLine('turning off the camera.'); } public void Rotate(int degrees) { Console.WriteLine('Rotating the camera by {0} degrees.', degrees); } }
新建Light类,增加一些方法实现: public class Light { public void TurnOff() { Console.WriteLine('Turning on the light.'); } public void TurnOn() { Console.WriteLine('Turning off the light.'); } public void ChangeBulb() { Console.WriteLine('changing the light-bulb.'); } }
根据上面的方法,增加Sensor与Alarm类,如下图
添加实现类,执行主方法,如下图:
运行程序,得到执行结果。
设计模式学习需要认真把握概念,多多练习实例