Skip to content

Instantly share code, notes, and snippets.

@Atsumi3
Last active January 27, 2016 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Atsumi3/2c5dc3195458b038a287 to your computer and use it in GitHub Desktop.
Save Atsumi3/2c5dc3195458b038a287 to your computer and use it in GitHub Desktop.
// Factory Method
public interface Human {
String getName();
}
/// Tanaka Factory
sealed class TanakaImpl : Human {
public string getName() {
return "Tanaka";
}
}
sealed public class TanakaFactory {
public static Human getInstance() {
return new TanakaImpl();
}
}
/// Tanaka Factory
sealed class YamadaImpl : Human {
public string getName() {
return "Yamada";
}
}
sealed public class YamadaFactory {
public static Human getInstance() {
return new YamadaImpl();
}
}
Human human = TanakaFactory.getInstance();
Console.WriteLine(human.getName()); // Tanaka
human = YamadaFactory.getInstance();
Console.WriteLine(human.getName()); // Yamada
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment