zoukankan      html  css  js  c++  java
  • 桥接模式

    桥接模式:将对象部分与它的实现部分分离,使它们可以独立的变化。

    结构图:

     

        class Abstraction
        {
            protected Implementor implementor;

            public void SetImplementor(Implementor implementor)
            {
                this.implementor = implementor;
            }

            public virtual void Operation()
            {
                implementor.Operation();
            }
        }

        class RefinedAbstraction : Abstraction
        {
            public override void Operation()
            {
                implementor.Operation();
            }
        }
     
        abstract class Implementor
        {
            public abstract void Operation();
        }
        class ConcreteImplementorA : Implementor
        {
            public override void Operation()
            {
                //throw new NotImplementedException();
                Console.WriteLine("具体实现A的方法执行");
            }
        }
     
        class ConcreteImplementorB : Implementor
        {
            public override void Operation()
            {
                //throw new NotImplementedException();
                Console.WriteLine("具体实现B的方法执行");
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                Abstraction ab = new RefinedAbstraction();

                ab.SetImplementor(new ConcreteImplementorA());
                ab.Operation();

                ab.SetImplementor(new ConcreteImplementorB());
                ab.Operation();

                Console.ReadKey();
            }
        }
  • 相关阅读:
    AUSU 安装Win10注意事项
    华硕笔记本无法设置U盘启动,快捷启动不能识别
    postgres 得到所有表空间 和 表空间的位置
    python 远程链接、搜索与下载
    python 读取 postgreSQL 数据保存CSV文件
    weka 初练之 文本分类
    基于springMVC+mybatis的实践记录
    简单的springMVC + mybatis 编写程序流程
    sql查询 生成列号
    通过资源文件 验证拦截机制
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2621111.html
Copyright © 2011-2022 走看看