Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active August 11, 2016 05:41
Show Gist options
  • Save KentarouKanno/c160644162be29e0500ef8c453bac93a to your computer and use it in GitHub Desktop.
Save KentarouKanno/c160644162be29e0500ef8c453bac93a to your computer and use it in GitHub Desktop.
Facade

Facade

・複数のクラス群からなるサブシステムにアクセスするための、インタフェースを提供する
・異なるサブシステムを単純な操作だけを持った Facade クラスで結び、サブシステム間の独立性を高める事を目的とする
(インタフェースを簡素化する)
・Facade とは、正面という意味

参考URL: Adapter, Facade, Proxy パターンの違いのメモ

class Target {
    func printInt(num: Int) {
        print(num)
    }
    
    func printString(str: String) {
        print(str)
    }
}

class Facade {
    var target: Target!
    
    init(target: Target) {
        self.target = target
    }
    
    func print(num: Int) {
        target.printInt(num)
    }
}

var target = Target()

var facade = Facade(target: target)
facade.print(5)

// 実行されるのはTargetのprintInt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment