This article mainly introduces the relevant information about the detailed explanation of the bridge mode in Java - the object structural mode. I hope that through this article you can master this part of the knowledge. Friends in need can refer to it
## Bridge pattern in #Java——Detailed explanation of examples of object structural pattern
1. Intention
2. Applicability
3. Structure
public interface Implementor { /** * 实现抽象部分的具体方法 */ public void operationImpl(); }
public class ConcreteImplementorA implements Implementor { @Override public void operationImpl() { System.out.println("ConcreteImplementorA"); } }
public class ConcreteImplementorB implements Implementor { @Override public void operationImpl() { System.out.println("ConcreteImplementorB"); } }
public abstract class Abstraction { private Implementor mImplementor; /** * 通过实现部分对象的引用构造抽象部分的对象 * * @param implementor 实现部分对象的引用 */ public Abstraction(Implementor implementor){ mImplementor = implementor; } public void operation(){ mImplementor.operationImpl(); } }
public class RefinedAbstraction extends Abstraction { /** * 通过实现部分对象的引用构造抽象部分的对象 * * @param implementor 实现部分对象的引用 */ public RefinedAbstraction(Implementor implementor) { super(implementor); } public void refinedOperation(){ //对 Abstraction中的方法进行扩展。 System.out.println("refinedOperation"); operation(); } }
public class Client { public static void main(String[] args){ Abstraction abstraction = new RefinedAbstraction(new ConcreteImplementorA()); abstraction.operation(); } }
The above is the detailed content of An example of object structural pattern of bridge pattern in Java. For more information, please follow other related articles on the PHP Chinese website!