コード例 #1
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            ICreditCard creditCard = new PlatinumFactory().CreateProduct();

            if (creditCard != null)
            {
                Console.WriteLine("Card Type : " + creditCard.GetCardType());
                Console.WriteLine("Credit Limit : " + creditCard.GetCreditLimit());
                Console.WriteLine("Annual Charge :" + creditCard.GetAnnualCharge());
            }
            else
            {
                Console.Write("Invalid Card Type");
            }
            Console.WriteLine("--------------");

            creditCard = new TitaniumFactory().CreateProduct();
            if (creditCard != null)
            {
                Console.WriteLine("Card Type : " + creditCard.GetCardType());
                Console.WriteLine("Credit Limit : " + creditCard.GetCreditLimit());
                Console.WriteLine("Annual Charge :" + creditCard.GetAnnualCharge());
            }
            else
            {
                Console.Write("Invalid Card Type");
            }
            Console.WriteLine("--------------");

            creditCard = new GoldFactory().CreateProduct();
            if (creditCard != null)
            {
                Console.WriteLine("Card Type : " + creditCard.GetCardType());
                Console.WriteLine("Credit Limit : " + creditCard.GetCreditLimit());
                Console.WriteLine("Annual Charge :" + creditCard.GetAnnualCharge());
            }
            else
            {
                Console.Write("Invalid Card Type");
            }
            Console.WriteLine("--------------");
            Console.Read();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            ICardFactory factory = null;

            Console.Write("Enter the card type you would like to visit: ");
            string cardType = Console.ReadLine();

            if (cardType != null)
            {
                switch (cardType.ToLower())
                {
                case "moneyback":
                    factory = new MoneyBackFactory(5000, 0);
                    break;

                case "titanium":
                    factory = new TitaniumFactory(10000, 300);
                    break;

                case "platinum":
                    factory = new PlatinumFactory(50000, 500);
                    break;

                default:
                    break;
                }
            }

            if (factory != null)
            {
                ICreditCard creditCard = factory.GetCreditCard();
                Console.WriteLine($"\n Your card details are : \n");
                Console.WriteLine("Card Type: {0}\nCredit Limit: {1}\nAnnual Charge: {2}",
                                  creditCard.CardType, creditCard.CreditLimit, creditCard.AnnualCharge);
            }

            Console.ReadKey();
        }