美文网首页
桥接模式(Bridge)

桥接模式(Bridge)

作者: bobcorbett | 来源:发表于2017-08-16 09:51 被阅读0次

桥接模式(Bridge),将抽象部分与它的实现部分分离,使它们都可以独立地变化。

主方法

public class main {
    public static void main(String[] args) {
        Abstraction ab = new RefinedAbstraction();

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

        ab.setImplementor(new ConcreteImplementorB());
        ab.Operation();
    }
}

操作功能抽象类

/**
 * 功能实现类
 */
public abstract class Implementor {
    public abstract void operation();
}

操作派生类

/**
 * 派生类A
 */
public class ConcreteImplementorA extends Implementor {
    public void operation() {
        System.out.println("具体实现A的方法执行");
    }
}
/**
 * 派生类B
 */
public class ConcreteImplementorB extends Implementor {
    public void operation() {
        System.out.println("具体实现B的方法执行");
    }
}

抽象类

/**
 * 抽象类
 */
public class Abstraction {
    protected Implementor implementor;

    public Implementor getImplementor() {
        return implementor;
    }

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

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

被提炼的抽象类

public class RefinedAbstraction extends Abstraction {
    public void Operation() {
        implementor.operation();
    }
}

相关文章

  • 设计模式解析—桥接设计模式

    桥接模式(Bridge Pattern)定义和使用场景 定义桥接模式(Bridge Pattern):将抽象部分...

  • docker的三种网络模式

    桥接模式:bridge

  • 桥接模式

    设计模式:桥接模式(Bridge)

  • 结构型-桥接(Bridge)

    桥接(Bridge) [TOC] 定义 桥梁模式(Bridge Pattern)也叫做桥接模式,是一个比较简单的模...

  • 设计模式-桥接模式

    设计模式-桥接模式 定义 桥接模式(Bridge Pattern)也称为桥梁模式、接口(Interface)模式或...

  • 10-桥接模式

    桥接模式-Bridge Pattern【学习难度:★★★☆☆,使用频率:★★★☆☆】 处理多维度变化——桥接模式(...

  • 桥接模式

    桥接(Bridge)模式的定义如下:将抽象与实现分离,使它们可以独立变化。 桥接(Bridge)模式的优点是:由于...

  • 桥接模式-原理类图

    桥接模式(Bridge)-基本介绍 桥接模式(Bridge模式)是指:将实现与抽象放在两个不同的类层次中,使两个层...

  • 桥接模式(Bridge)

    定义它把事物对象和其具体行为、具体特征分离开来,使它们可以各自独立的变化。事物对象仅是一个抽象的概念。如“圆形”、...

  • 桥接模式-bridge

    将抽象部分与它的实现部分分离,使他们都可以独立地变化 效果及实现要点: 适用性: 在以下的情况下应当使用桥梁模式:...

网友评论

      本文标题:桥接模式(Bridge)

      本文链接:https://www.haomeiwen.com/subject/hlobrxtx.html