桥接(Bridge)模式的定义如下:将抽象与实现分离,使它们可以独立变化。它是用组合关系代替继承关系来实现,从而降低了抽象和实现这两个可变维度的耦合度。
public interface Implementor {
/**
* 功能描述:
* 〈具体操作的实现类〉
*
* @params : []
* @return : void
* @author : cwl
* @date : 2019/6/24 10:50
*/
void OperationImpl();
}
public abstract class Abstraction {
protected Implementor imple;
protected Abstraction(Implementor imple) {
this.imple=imple;
}
public abstract void Operation();
}
public class RefinedAbstraction extends Abstraction {
protected RefinedAbstraction(Implementor imple) {
super(imple);
}
@Override
public void Operation() {
System.out.println("扩展抽象化(Refined Abstraction)角色被访问" );
imple.OperationImpl();
}
}
public class ConcreteImplementorA implements Implementor {
@Override
public void OperationImpl() {
System.out.println("具体实现化(Concrete Implementor)角色被访问" );
}
}
public class BridgeTest {
public static void main(String[] args) {
Implementor imple=new ConcreteImplementorA();
Abstraction abs=new RefinedAbstraction(imple);
abs.Operation();
}
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有