브리지 패턴 (Bridge pattern)
브리지 패턴 (Bridge pattern)
- 구현부에서 추상층을 분리하여 각자 독립적으로 변형 & 확장이 가능, 즉 기능과 구현에 대해서 두 개를 별도의 클래스로 구현
 - 기능 클래스 계층과 구현 클래스 사이에 다리를 놓는다
 
구조

- Implementor : 기능 구현을 위한 인터페이스
 - ConcreteImplementor : 실제 기능 구현
 - Abstraction : 기능 계층의 최상위 클래스
 - RefindAbstraction : 기능 확장
 
예제

Implementor : 기능 구현을 위한 인터페이스
public interface MakeHandler {
    public void prepareIngredient();
    public void stuffingIngredient();
}
ConcreteImplementor : 실제 기능 구현
public class PotatoHotdogMethod implements MakeHandler {
    public void prepareIngredient() {
        System.out.println("감자 준비");
    }
    public void stuffingIngredient() {
        System.out.println("감자를 꼬치에 꽂는다");
    }
}
public class CheeseHotdogMethod implements MakeHandler {
    public void prepareIngredient() {
        System.out.println("치즈 준비");
    }
    public void stuffingIngredient() {
        System.out.println("치즈를 꼬치에 꽂는다");
    }
}
Abstraction : 기능 계층의 최상위 클래스
public abstract class HotDog {
    private MakeHandler makeHandler;
    public HotDog(MakeHandler makeHandler) {
        this.makeHandler = makeHandler;
    }
    public void prepareIngredient() {
        makeHandler.prepareIngredient();
    }
    public void stuffingIngredient() {
        makeHandler.stuffingIngredient();
    }
    public abstract void fry();
}
RefindAbstraction : 기능 확장
public class PotatoHotDog extends HotDog {
    public PotatoHotDog(PotatoHotdogMethod potatoHotDogMethod) {
        super(potatoHotDogMethod);
    }
    @Override
    public void fry() {
        System.out.println("감자핫도그 튀기기 전 준비");
    }
}
public class CheeseHotDog extends HotDog {
    public CheeseHotDog(CheeseHotdogMethod cheeseHotdogMethod) {
        super(cheeseHotdogMethod);
    }
    @Override 
    public void fry() {
        System.out.println("치즈핫도그 튀기기 전 준비");
    }
}
public class Main {
    public static void main(String args[]) {
        HotDog cheeseHotDog = new CheeseHotDog(new CheeseHotdogMethod());
        HotDog potatoHotDog = new PotatoHotDog(new PotatoHotdogMethod());
        cheeseHotDog.fry();
        cheeseHotDog.prepareIngredient();
        cheeseHotDog.stuffingIngredient();
    }
}