Last active
February 8, 2016 19:15
-
-
Save 53ningen/42e30144104b2d7f8fb6 to your computer and use it in GitHub Desktop.
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 Service { | |
func addPrefix(name: String) -> String | |
} | |
public class MsService: Service { | |
public func addPrefix(name: String) -> String { return "Ms." + name } | |
} | |
public class MrService: Service { | |
public func addPrefix(name: String) -> String { return "Mr." + name } | |
} | |
public class Client { | |
private let service: Service //=> コンストラクタから依存オブジェクトを差し込んでもらう | |
public init(service: Service) { self.service = service } //=> おわかり頂けただろうか... | |
public func callName(name: String) { print(service.addPrefix(name)) } | |
} | |
let client = Client(service: MsService()) | |
client.callName("Cocoa") //=> Ms.Cocoa |
Author
53ningen
commented
Feb 8, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment