Last active
March 15, 2016 16:06
-
-
Save 53ningen/a6df95dbe8e7f503d1fe to your computer and use it in GitHub Desktop.
Playgroundで動きます (Xcode7.2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol A { | |
func getA() -> String | |
} | |
private class AImpl: A { | |
private func getA() -> String { | |
return "a" | |
} | |
} | |
public protocol AB { | |
func getAB() -> String | |
} | |
private class ABUsingA: AB { | |
private let a: A | |
private init(a: A) { | |
self.a = a | |
} | |
private func getAB() -> String { | |
return a.getA() + "b" | |
} | |
} | |
private class SimpleAB: AB { | |
private func getAB() -> String { | |
return "AB" | |
} | |
} | |
public protocol AComponent { | |
static var a: A { get } | |
} | |
public protocol DefaultAComponent: AComponent {} | |
extension DefaultAComponent { | |
public static var a: A { | |
return AImpl() | |
} | |
} | |
public protocol ABComponent { | |
static var ab: AB { get } | |
} | |
public protocol DefaultABComponent: ABComponent {} | |
extension DefaultABComponent where Self: AComponent { | |
public static var ab: AB { | |
return ABUsingA(a: a) | |
} | |
} | |
public protocol SimpleABComponent: ABComponent { | |
static var ab: AB { get } | |
} | |
extension SimpleABComponent { | |
public static var ab: AB { | |
return SimpleAB() | |
} | |
} | |
public typealias Components = protocol<AComponent, ABComponent> | |
public enum DefaultComponents: DefaultAComponent, DefaultABComponent {} | |
let defaultComponents: Components.Type = DefaultComponents.self | |
defaultComponents.a.getA() | |
defaultComponents.ab.getAB() | |
public enum SimpleComponents: DefaultAComponent, SimpleABComponent {} | |
let simpleComponents: Components.Type = SimpleComponents.self | |
simpleComponents.a.getA() | |
simpleComponents.ab.getAB() | |
Author
53ningen
commented
Mar 15, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment