Last active
January 27, 2016 06:13
-
-
Save Atsumi3/b5ca2b6e55070569f080 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 interface Human { | |
String getName(); | |
} | |
/// Tanaka Factory | |
final class TanakaImpl implements Human { | |
@Override public String getName() { | |
return "Tanaka"; | |
} | |
} | |
final public class TanakaFactory { | |
public static Human getInstance() { | |
return new TanakaImpl(); | |
} | |
} | |
/// Yamada Factory | |
final class YamadaImpl implements Human { | |
@Override public String getName() { | |
return "Yamada"; | |
} | |
} | |
final public class YamadaFactory{ | |
public static Human getInstance() { | |
return new YamadaImpl(); | |
} | |
} | |
Human human = TanakaFactory.getInstance(); | |
System.out.println(human.getName); // Tanaka | |
human = YamadaFactory.getInstance(); | |
System.out.println(human.getName); // Yamada |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment