コード例 #1
0
        static void Main(string[] args)
        {
            Console.Write("Payment Method: ");
            var method = Console.ReadLine();

            Computer computer;

            var order = new Order
            {
                AmountOfCores = 4,
                AmountOfRam = 32,
                CpuFrequency = 3.0m,
                DriveType = "ssd"
            };

            var processingService = new OrderProcessingService();

            if (method.ToLower() == "cash")
            {
                computer = processingService.MakeCashPurchase(order, 1500m);
            }
            else
            {
                computer = processingService.MakeCreditPurchase(order);
            }

            GiveComputerToCustomer(computer);

            Console.Read();
        }
コード例 #2
0
        public Computer Build(Order order, ComputerBuilder builder)
        {
            builder.SetCores(order.AmountOfCores);
            builder.SetCpuFrequency(order.CpuFrequency);
            builder.SetRam(order.AmountOfRam);
            builder.SetDriveType(order.DriveType);

            Console.WriteLine("Built Computer.");

            return builder.GetComputer();
        }
コード例 #3
0
        public Computer MakeCashPurchase(Order order, decimal amount)
        {
            var register = new CashRegisterService();
            register.OpenDrawer();
            var change = register.MakeChange(order.Price, amount);

            var computer = store.Build(order, computerBuilder);

            factory.PlaceOrder(order);

            return computer;
        }
コード例 #4
0
        public Computer MakeCreditPurchase(Order order)
        {
            var credit = new CreditProcessingService();

            if (!credit.HasCreditAvailable(order.Price))
            {
                throw new Exception("Customer does not have avaiable credit.");
            }

            credit.MakePurchase(order.Price);

            var computer = store.Build(order, computerBuilder);

            factory.PlaceOrder(order);

            return computer;
        }
コード例 #5
0
 public void PlaceOrder(Order order)
 {
     Console.WriteLine("Ordered parts for inventory.");
 }