LoginSignup
0
0

More than 3 years have passed since last update.

bridge pattern

ケース

抽象と実装を分離する。
抽象のみで組み立てて、実装は置き換え可能にする。

実装対象

Client
Abstraction
RefinedAbstraction
Implementor
ConcreteImplementorA

example

class WindowAbstraction {
    private let figureImplementor: FigureImplementorProtocol

    init(figureImplementor: FigureImplementorProtocol) {
        self.figureImplementor = figureImplementor
    }

    func drawRect() {
        figureImplementor.drawLine()
        figureImplementor.drawLine()
        figureImplementor.drawLine()
        figureImplementor.drawLine()
    }
}

class IconWindow: WindowAbstraction {
    func drawBorder() {
        // some process
        drawRect()
        // some process
    }
}

protocol FigureImplementorProtocol {
    func drawLine()
}

class : AndroidFigureImplementor {
    func drawLine() {
        // some exact process
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0