FactoryMethodPattern
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
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