Last active
January 27, 2016 06:13
-
-
Save Atsumi3/c2366c6f7eb447a8ac0e to your computer and use it in GitHub Desktop.
This file contains 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
// Factory Method | |
public protocol Human { | |
func getName()->String; | |
} | |
/// Tanaka Factory | |
final class TanakaImpl : Human { | |
func getName() -> String { | |
return "Tanaka"; | |
} | |
} | |
final public class TanakaFactory { | |
public static func getInstance()-> Human { | |
return TanakaImpl(); | |
} | |
} | |
/// Yamada Factory | |
final class YamadaImpl : Human { | |
func getName() -> String { | |
return "Yamada"; | |
} | |
} | |
final public class YamadaFactory { | |
public static func getInstance()-> Human { | |
return YamadaImpl(); | |
} | |
} | |
var human : Human = TanakaFactory.getInstance(); | |
print(human.getName()); // Tanaka | |
human = YamadaFactory.getInstance(); | |
print(human.getName()); // Yamada |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment