示例#1
0
        static void Main(string[] args)
        {
            ComputerFactory factory = null;

            if (args.Length > 0 && args[0] == "BrandX")
            {
                factory = new BrandXFactory();
            }
            else
            {
                factory = new ConcreteComputerFactory();
            }

            new ComputerAssembler().AssembleComputer(factory);


            // Add in Product Factory
            var product = new Product();

            Console.WriteLine("Enter a product name: ");
            product.Name        = Console.ReadLine();
            product.Description = "A New Product";
            Console.WriteLine("Enter a price: ");
            product.Price = Convert.ToInt32(Console.ReadLine());

            // With Bank using BestForMe
            PaymentProcessor payment = new PaymentProcessor();

            payment.MakePayment(PaymentMethod.BEST_FOR_ME, product);

            // Try with PayPal has access to all the payment methods
            PaymentProcessor2 paypal = new PaymentProcessor2();

            paypal.MakePayment(PaymentMethod.PAYPAL, product);

            // Added BillDesk Payment
            PaymentProcessor2 payment2 = new PaymentProcessor2();

            payment2.MakePayment(PaymentMethod.BILL_DESK, product);

            Console.WriteLine(product.Name + ' ' + product.Price);

            Console.WriteLine("Now the Cars portion of the program.");
            Console.Read();

            // Cars
            var fordFiestaFactory = new FordFiestaFactory();
            var fordFiesta        = fordFiestaFactory.CreateCar("Blue");

            Console.WriteLine("Brand: {0} \nModel: {1} \nColor: {2}", fordFiesta.Make, fordFiesta.Model, fordFiesta.Color);
            Console.Read();

            Console.WriteLine("\n");
            ICarSupplier objCarSupplier = CarFactory.GetCarInstance(2);

            objCarSupplier.GetCarModel();
            Console.WriteLine(" and color is " + objCarSupplier.CarColor);
            Console.Read();
            Console.Read();
        } //Main
示例#2
0
        static void Main(string[] args)
        {
            var product = new Product()
            {
                Name = "Xbox One", Description = "500 GB w Kinect", Price = 350.0M,
            };

            var processor = new PaymentProcessor();

            processor.MakePayment(PaymentMethod.BankOne, product);
            processor.MakePayment(PaymentMethod.BankTwo, product);
            processor.MakePayment(PaymentMethod.BestForMe, product);

            var processor2 = new PaymentProcessor2();

            processor2.MakePayment(PaymentMethod.PayPal, product);
            processor2.MakePayment(PaymentMethod.BillDesk, product);

            System.Console.ReadKey();
        }