See the author’s blog for a detailed explanation of “bridge mode.

“Design patterns” part 3 structural design patterns chapter 10 bridge patterns (A: C++ implementation)

This article is a Java implementation of the “bridge pattern”.

Step 1: Implement The Role: Defines the interface that implements the role for the extended abstract role to call.

package com;

public interface Implementor {
    public void OperationIm(a);
}
Copy the code

Step 2: Concrete Implementor role: Give the Concrete implementation of the interface to implement the role.

package com;

public class ConcreteImpementorA implements Implementor{

	@Override
	public void OperationIm(a) {
		System.out.println("OperationImp_A"); }}package com;

public class ConcreteImpementorB implements Implementor{

	@Override
	public void OperationIm(a) {
		System.out.println("OperationImp_B"); }}Copy the code

Step 3: Abstraction of character

package com;

public abstract class Abstraction {
	
	protected Implementor imple;
	protected Abstraction(Implementor imple){
		this.imple=imple;
	}
	
	public abstract void Operation(a);   
}
Copy the code

Step 4: Refine Abstraction character

package com;

public class RefinedAbstraction extends Abstraction{

	protected RefinedAbstraction(Implementor imple) {
		super(imple);
	}

	@Override
	public void Operation(a) { imple.OperationIm(); }}Copy the code

The result is as follows: