Skip to content

Instantly share code, notes, and snippets.

@53ningen
Created February 8, 2016 19:16
Show Gist options
  • Save 53ningen/b063c8b545fc97888c47 to your computer and use it in GitHub Desktop.
Save 53ningen/b063c8b545fc97888c47 to your computer and use it in GitHub Desktop.
protocol C { func appendC(s: String) -> String }
class CImpl: C {
private let b: B
init(b: B) { self.b = b } //⚡️ CImpl は B のインスタンスを要求する
func appendC(s: String) -> String { return b.appendB(s) + "c" }
}
protocol B { func appendB(s: String) -> String }
class BImpl: B {
private let a: A
init(a: A) { self.a = a } //⚡️ BImpl は A のインスタンスを要求する
func appendB(s: String) -> String { return a.appendA(s) + "b" }
}
protocol A { func appendA(s: String) -> String }
class AImpl: A { func appendA(s: String) -> String { return s + "a" } }
let c: C = CImpl(b: BImpl(a: AImpl())) // 👈 う〜ん、この・・・。
c.appendC("@")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment