设计模式学习笔记--外观模式

 1 using System;
 2 
 3 namespace Facade
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/25 7:38:52 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// Appliance说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public class Appliance
12     {
13         private string name;
14 
15         protected Appliance(string name)
16         {
17             this.name = name;
18         }
19 
20         public void On()
21         {
22             Console.WriteLine("打开了"+name);
23         }
24 
25         public void Off()
26         {
27             Console.WriteLine("关闭了"+name);
28         }
29     }
30 }
View Code
 1 using System;
 2 
 3 namespace Facade
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/25 7:36:17 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// Television说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public class Television:Appliance
12     {
13         public Television(string name)
14             : base(name)
15         { }
16     }
17 }
View Code
 1 using System;
 2 
 3 namespace Facade
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/25 7:41:49 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// Light说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public class Light:Appliance
12     {
13         public Light(string name)
14             : base(name)
15         { }
16     }
17 }
View Code
 1 using System;
 2 
 3 namespace Facade
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/25 7:42:39 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// AirCondition说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public class AirCondition:Appliance
12     {
13         public AirCondition(string name)
14             : base(name)
15         { }
16     }
17 }
View Code
 1 using System;
 2 
 3 namespace Facade
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/25 7:43:15 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// Screen说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public class Screen:Appliance
12     {
13         public Screen(string name)
14             : base(name)
15         { }
16     }
17 }
View Code
 1 using System;
 2 
 3 namespace Facade
 4 {
 5     /// <summary> 
 6     /// 作者:bzyzhang
 7     /// 时间:2016/5/25 7:43:50 
 8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
 9     /// WatchTvSwtichFacade说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
10     /// </summary> 
11     public class WatchTvSwtichFacade
12     {
13         Appliance television;
14         Appliance light;
15         Appliance airCondition;
16         Appliance screen;
17 
18         public WatchTvSwtichFacade()
19         {
20             television = new Television("电视");
21             light = new Light("电灯");
22             airCondition = new AirCondition("空调");
23             screen = new Screen("银幕");
24         }
25 
26         public void On()
27         {
28             television.On();
29             light.On();
30             airCondition.On();
31             screen.On();
32         }
33 
34         public void Off()
35         {
36             television.Off();
37             light.Off();
38             airCondition.Off();
39             screen.Off();
40         }
41     }
42 }
View Code
 1 namespace Facade
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             WatchTvSwtichFacade watchTvSwtichFacade = new WatchTvSwtichFacade();
 8 
 9             watchTvSwtichFacade.On();
10             watchTvSwtichFacade.Off();
11         }
12     }
13 }
View Code

 

posted @ 2016-05-25 15:32  bzyzhang  阅读(119)  评论(0编辑  收藏  举报