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();
            }
        }
  • 相关阅读:
    docker怎么修改之前run时的env
    yum安装mysql
    springboot服务的Dockerfile
    openssh升级到8.4
    rpm与yum执行无反应
    ubuntn离线安装docker-ce
    centos7部署docker
    解决5版本的elasticsearch-head连接6版本的elasticsearch查询不到数据问题
    docker搭建elasticsearch:7.6.2并开启x-pack
    原生js 实现图片的拖拽缩放
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2621111.html
Copyright © 2011-2022 走看看