zoukankan      html  css  js  c++  java
  • 设计模式学习笔记--外观模式

     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
  • 相关阅读:
    HBase编程 API入门系列之delete.deleteColumn和delete.deleteColumns区别(客户端而言)(4)
    证明,为什么HBase在创建表时,列簇是必须要,列可不要?
    HBase编程 API入门系列之delete(客户端而言)(3)
    HBase编程 API入门系列之get(客户端而言)(2)
    HBase编程 API入门系列之put(客户端而言)(1)
    Hadoop HBase概念学习系列之HBase里的时间戳(二十六)
    Zookeeper(1、3、5节点)集群安装
    hbase无法启动,The node /hbase is not in ZooKeeper
    HBase、Hive、MapReduce、Hadoop、Spark 开发环境搭建后的一些步骤(export导出jar包方式 或 Ant 方式)
    Hadoop HBase概念学习系列之hbase shell中执行java方法(高手必备)(二十五)
  • 原文地址:https://www.cnblogs.com/bzyzhang/p/5527199.html
Copyright © 2011-2022 走看看