zoukankan      html  css  js  c++  java
  • 《大话设计模式》学习笔记18:桥接模式

      

      

    手机品牌及手机软件示例:

      

    1.Implementor:

        public abstract class HandsetSoft
        {
            public abstract void Run();
        }

    2.ConcreteImplementor(以游戏类为例):

        public class HandsetGame:HandsetSoft
        {
            public override void Run()
            {
                Console.WriteLine("运行手机游戏");
            }
        }

    3.Abstraction:

        public abstract class HandsetBrand
        {
            protected HandsetSoft handsetSoft;
            public void SetHandsetSoft(HandsetSoft handsetSoft)
            {
                this.handsetSoft = handsetSoft;
            }
            public abstract void Run();
        }

    4.RefinedAbstraction(以手机品牌N为例):

        public class HandsetBrandN:HandsetBrand
        {
            public override void Run()
            {
                handsetSoft.Run();
            }
        }

    5.客户端代码:

        class Program
        {
            static void Main(string[] args)
            {
                HandsetBrand handsetBrand;
    
                handsetBrand = new HandsetBrandN();
                handsetBrand.SetHandsetSoft(new HandsetGame());
                handsetBrand.Run();
                handsetBrand.SetHandsetSoft(new HandsetAddressList());
                handsetBrand.Run();
    
                handsetBrand = new HandsetBrandM();
                handsetBrand.SetHandsetSoft(new HandsetGame());
                handsetBrand.Run();
                handsetBrand.SetHandsetSoft(new HandsetAddressList());
                handsetBrand.Run();
            }
        }

      “将抽象部分与它的现实部分分离”即实现系统可能有多角度分类,每一种分类都有可能变化,那么就把这种多角度分离出来让它们独立变化,减少它们之间的耦合。

  • 相关阅读:
    register_shutdown_function
    字节转换
    考虑 PHP 5.0~5.6 各版本兼容性的 cURL 文件上传
    linux--svn checkout
    linux命令
    linux---mysql忘记密码
    array_merge函数的注意事项
    逻辑卷使用记录笔记
    系统设计时关于性能问题处理的几点心得
    SSH防暴力破解脚本
  • 原文地址:https://www.cnblogs.com/walden1024/p/4523984.html
Copyright © 2011-2022 走看看