橋接模式git
public interface IImplementor { void print(); }
public class ImplementorA implements IImplementor{ @Override public void print() { System.out.println(this.getClass().getSimpleName()); } } public class ImplementorB implements IImplementor{ @Override public void print() { System.out.println(this.getClass().getSimpleName()); } }
public abstract class Abstraction { IImplementor implementor; public void print(){ implementor.print(); } }
public class ConcreteAbstraction extends Abstraction{ public ConcreteAbstraction(IImplementor implementor){ super.implementor = implementor; } public void print(){ super.print(); } }
public static void main(String[] args) { Abstraction abstraction = new ConcreteAbstraction(new ImplementorA()); abstraction.print(); abstraction = new ConcreteAbstraction(new ImplementorB()); abstraction.print(); }
ImplementorA ImplementorB
https://github.com/Seasons20/DisignPattern.git
ENDgithub