public static void WithoutUsingFactoryDP(string cardType) { ICreditCard cardDetails = null; if (cardType == "MoneyBack") { cardDetails = new MoneyBack(); } else if (cardType == "Titanium") { cardDetails = new Titanium(); } else if (cardType == "Platinum") { cardDetails = new Platinum(); } if (cardDetails != null) { Console.WriteLine("CardType : " + cardDetails.GetCardType()); Console.WriteLine("CreditLimit : " + cardDetails.GetCreditLimit()); Console.WriteLine("AnnualCharge :" + cardDetails.GetAnnualCharge()); } else { Console.Write("Invalid Card Type"); } }
public static ICreditCard GetCardInstance(string cardType) { ICreditCard creditCard = null; if (cardType == "MoneyBack") { creditCard = new MoneyBack(); } else if (cardType == "Titanium") { creditCard = new Titanium(); } else if (cardType == "Platinum") { creditCard = new Platinum(); } return(creditCard); }