Skip to content

Instantly share code, notes, and snippets.

@codinko
Last active December 29, 2015 18:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save codinko/1392b114ca9fc6258d5c to your computer and use it in GitHub Desktop.
FactoryMethodPattern
class CustomerFactory
{
public static ICustomer GetCustomer(int i)
{
switch (i)
{
case 1:
GoldCustomer goldCustomer = new GoldCustomer();
goldCustomer.GoldOperation();
goldCustomer.AddPoints();
goldCustomer.AddDiscount();
return goldCustomer;
case 2:
SilverCustomer silverCustomer = new SilverCustomer();
silverCustomer.SilverOperation();
silverCustomer.AddPoints();
silverCustomer.AddDiscount();
return silverCustomer;
default: return null;
}
}
}
//Client Code
ICustomer c = CustomerFactory.GetCustomer(someIntegerValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment