public void Run() { // Generally we will get the Card Type from UI // Here we are hardcoded the card type string cardType = "MoneyBack"; CreditCard cardDetails = null; // Based of the CreditCard Type we are creating the // appropiate type instrance using if else condition 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.WriteLine("Invalid Card Type"); } Console.ReadLine(); }
protected override CreditCard MakeProduct() { CreditCard product = new Platinum(); return(product); }