示例#1
0
        private void AddHDD_button_Click(object sender, EventArgs e)
        {
            ILaptop tempLaptop = new HDD(laptopBeingEdited);

            laptopBeingEdited = tempLaptop;
            updatePurchaseInfo(laptopBeingEdited.GetProductDetails());
        }
        static async Task Main(string[] args)
        {
            ILaptop laptop = null;

            Console.WriteLine("1. Factory method - using interface...");
            CaseInterface.IHPLaptopFactory interfaceFactory = null;
            interfaceFactory = new CaseInterface.EnvyHPLaptopFactory();
            laptop           = interfaceFactory.CreateHPLaptop();
            Console.WriteLine(laptop.Description);

            Console.WriteLine("2. Factory method - using abstract class...");
            CaseAbstractClass.HPLaptopFactory abstractFactory = null;
            abstractFactory = new CaseAbstractClass.PavilionHPLaptopFactory();
            laptop          = abstractFactory.MakeLaptop();
            Console.WriteLine(laptop.Description);

            Console.WriteLine("3. Factory method - using private constructor...");
            var laptop2 = LaptopPrivateConstructor.NewEnvyLaptop("2GH", 1);

            Console.WriteLine("4. Factory method - using asynchronous...");
            LaptopAsynchronous laptop3 = await LaptopAsynchronous.NewEnvyLaptopAsync("2GH", 1);

            Console.WriteLine("5. Factory method - using inner class...");
            var laptop4 = LaptopInnerClass.Factory.NewEnvyLaptop("2GH", 1);
        }
示例#3
0
        public void ProcesarCotizacion()
        {
            ILaptop    laptop      = null;
            IImpresora impresora   = null;
            int        diasEntrega = 0;
            decimal    importe     = 0M;

            switch (this.producto)
            {
            case "Laptop":
                laptop      = this.tiendaProductos.GenerarInstanciaLaptop();
                importe     = laptop.CalcularImporte(this.cantidad);
                diasEntrega = laptop.ObtenerDiasEntrega();

                break;

            case "Impresora":
                impresora   = this.tiendaProductos.GenerarInstanciaImpresora();
                importe     = impresora.CalcularImporte(this.cantidad);
                diasEntrega = impresora.ObtenerDiasEntrega();
                break;
            }
            this.imprimirMensaje(this.generarMensajeRequisicion(diasEntrega),
                                 this.generarMensajeCotizacion(importe));
        }
        public void AddingNegativeValueForChargeShouldDropCurrentCharge()
        {
            battery.Percentage = 100;
            laptop             = new Laptop(motherboard, battery);
            laptop.ChargeBattery(-1);

            Assert.AreEqual(99, battery.Percentage);
        }
        public void AddingNegativeValueBiggerThenCurrentValueShouldMakeCurrentChargeToZero()
        {
            battery.Percentage = 100;
            laptop             = new Laptop(motherboard, battery);
            laptop.ChargeBattery(-101);

            Assert.AreEqual(0, battery.Percentage);
        }
        public void AddingValueToCurrentValueShouldIncreaseCurrentCharge()
        {
            battery.Percentage = 50;
            laptop             = new Laptop(motherboard, battery);
            laptop.ChargeBattery(10);

            Assert.AreEqual(60, battery.Percentage);
        }
        public void ChargeShouldNeverBeBiggerThen100()
        {
            battery.Percentage = 50;
            laptop             = new Laptop(motherboard, battery);
            laptop.ChargeBattery(60);

            Assert.AreEqual(100, battery.Percentage);
        }
        public void AddingNUllPercentageShouldThrowReferenceNullExeption()
        {
            battery.Percentage = 50;
            laptop             = new Laptop(motherboard, battery);
            laptop.ChargeBattery(60);

            Assert.AreEqual(100, battery.Percentage);
        }
示例#9
0
        public override ILaptop CreateLaptop()
        {
            var cpu         = new Cpu64Bit(2);
            var harddrives  = new[] { new HardDrive(500, false, 0) };
            var ram         = new Ram(4);
            var motherboard = new MotherBoard(cpu, ram, harddrives, this.colorfullVideoCard);

            this.laptop = new Laptop(motherboard, this.battery);
            return(this.laptop);
        }
示例#10
0
 private void Laptop_listBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (Laptop_listBox.SelectedIndex >= 0 && Laptop_listBox.SelectedIndex <= laptopsBought.Count && laptopBeingEdited == null)
     {
         laptopBeingEdited = laptopsBought.ElementAt(Laptop_listBox.SelectedIndex);
         updatePurchaseInfo(laptopBeingEdited.GetProductDetails());
         toggleGui();
         re_edit_laptop = true;
     }
 }
示例#11
0
 string IVisitor.Visit(ILaptop e)
 {
     if (e is Lenove)
         return Visit((Lenove) e);
     if (e is Appel)
         return Visit((Appel) e);
     if (e is HP)
         return Visit((HP) e);
     return null;
 }
示例#12
0
        public override ILaptop CreateLaptop()
        {
            this.ram        = new Ram(8);
            this.cpu        = new Cpu32Bit(4);
            this.hardDrives = new[] { new HardDrive(1000, false, 0) };

            var motherboard = new MotherBoard(this.cpu, this.ram, this.hardDrives, this.colorfullVideoCard);

            this.laptop = new Laptop(motherboard, new LaptopBattery());

            return(this.laptop);
        }
示例#13
0
        public void Main()
        {
            ElectronicStoreClient e     = new ElectronicStoreClient();
            IDeviceFactory        apple = e.CheckProducts(Manufacturers.APPLE);

            ILaptop     macbookPro = apple.GetLaptop();
            ISmartPhone smartPhone = apple.GetSmartPhone();

            IDeviceFactory samsung  = e.CheckProducts(Manufacturers.SAMSUNG);
            ILaptop        galaxy   = samsung.GetLaptop();
            ISmartPhone    notebook = samsung.GetSmartPhone();
        }
示例#14
0
 public string Visit(ILaptop e)
 {
     if (e is Lenove)
     {
         return(Visit((Lenove)e));
     }
     if (e is Appel)
     {
         return(Visit((Appel)e));
     }
     if (e is HP)
     {
         return(Visit((HP)e));
     }
     return(null);
 }
示例#15
0
        public void Execute(string[] splittedCommand, IPC pc, ILaptop laptop, IServer server)
        {
            var commandName = splittedCommand[0];
            var commandArguments = int.Parse(splittedCommand[1]);

            if (commandName == "Charge")
            {
                laptop.ChargeBattery(commandArguments);
            }
            else if (commandName == "Process")
            {
                server.Process(commandArguments);
            }
            else if (commandName == "Play")
            {
                pc.Play(commandArguments);
            }
        }
示例#16
0
 //combo box
 private void metroComboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (metroComboBox1.SelectedIndex == 0)
     {
         laptop            = new Appel();
         pictureBox1.Image = LaptopStore.Properties.Resources.Apple;
         if (metroToggle1.Checked)
         {
             richTextBox1.Text = laptop.Accept(new DetailedDescription());
         }
         else
         {
             richTextBox1.Text = laptop.Accept(new BriefDescription());
         }
     }
     else if (metroComboBox1.SelectedIndex == 1)
     {
         laptop            = new Lenove();
         pictureBox1.Image = LaptopStore.Properties.Resources.Lenovo;
         if (metroToggle1.Checked)
         {
             richTextBox1.Text = laptop.Accept(new DetailedDescription());
         }
         else
         {
             richTextBox1.Text = laptop.Accept(new BriefDescription());
         }
     }
     else if (metroComboBox1.SelectedIndex == 2)
     {
         laptop            = new HP();
         pictureBox1.Image = LaptopStore.Properties.Resources.Hp;
         if (metroToggle1.Checked)
         {
             richTextBox1.Text = laptop.Accept(new DetailedDescription());
         }
         else
         {
             richTextBox1.Text = laptop.Accept(new BriefDescription());
         }
     }
 }
示例#17
0
 private void RemoveLaptop_button_Click(object sender, EventArgs e)
 {
     if (!re_edit_laptop)
     {
         toggleGui();
         laptopBeingEdited = null;
         Info_label.Text   = "0";
         listbox_purchase_info.Items.Clear();
     }
     else if (re_edit_laptop)
     {
         toggleGui();
         laptopBeingEdited = null;
         Info_label.Text   = "0";
         laptopsBought.RemoveAt(Laptop_listBox.SelectedIndex);
         Laptop_listBox.Items.RemoveAt(Laptop_listBox.SelectedIndex);
         listbox_purchase_info.Items.Clear();
         re_edit_laptop = false;
     }
 }
示例#18
0
        public static ILaptop fabrica(string laptop)
        {
            ILaptop interface1 = null;

            if (laptop == "MSI GL75")
            {
                interface1 = new MSI();
                interface1.mostrar();
            }
            if (laptop == "ASUS TUF Dash 15")
            {
                interface1 = new Asus();
                interface1.mostrar();
            }
            if (laptop == "Lenovo Legion 5")
            {
                interface1 = new Lenovo();
                interface1.mostrar();
            }
            return(interface1);
        }
示例#19
0
        private static void FactoryPatternSample()
        {
            Console.WriteLine("--Sample Factory Pattern--");
            ILaptopCreator lc = new DellXpsConcreteCreator();
            ILaptop        l  = lc.GetLaptop("");

            Console.WriteLine("Selected laptop is " + l.GetName() + " with a  price of " + l.GetPrice());

            l = lc.GetLaptop("15");
            Console.WriteLine("Selected laptop is " + l.GetName() + " with a  price of " + l.GetPrice());

            lc = new DellGSeriesConcreteCreator();
            l  = lc.GetLaptop("");
            Console.WriteLine("Selected laptop is " + l.GetName() + " with a  price of " + l.GetPrice());

            l = lc.GetLaptop("5");
            Console.WriteLine("Selected laptop is " + l.GetName() + " with a  price of " + l.GetPrice());

            lc = new DellVostroConcreteCreator();
            l  = lc.GetLaptop("");
            Console.WriteLine("Selected laptop is " + l.GetName() + " with a  price of " + l.GetPrice());
        }
示例#20
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a make - lenovo or dell");
            String make = Console.ReadLine();

            Console.WriteLine("Enter a budget");
            int budget = Convert.ToInt32(Console.ReadLine());

            //This singleton decides which factory to "fire up", based on the make (Dell, Lenovo etc.) that the customer requests
            FactoryCreatorSingleton myFactoryCreator = FactoryCreatorSingleton.GetInstance();

            ILaptopFactory requestedMakeFactory = myFactoryCreator.GetLaptopFactory(make);

            //Here the appropriate factory will produce the laptop based on the budget
            ILaptop requestedLaptop = requestedMakeFactory.MakeLaptop(budget);

            //ILaptop myLaptop = ProductFactory.makeProduct(budget);
            Console.WriteLine("Creating a laptop from " + requestedMakeFactory.GetFactoryName() + " of make " + requestedLaptop.GetMake() + " \n"
                              + " and model " + requestedLaptop.GetModel());

            Console.ReadLine();
        }
        /// <summary>
        /// Shows all workplace equipment of the company.
        /// </summary>
        /// <param name="company">Company.</param>
        static void ShowWorkplaceEquipment(Company company)
        {
            IWorkplaceEquipmentFactory workplaceEquipmentFactory = WorkplaceEquipmentFactories.GetFactory(company);

            if (workplaceEquipmentFactory == null)
            {
                Console.WriteLine("{0} company did not provide any information about workplace equipments.\n", company);
                return;
            }

            Console.WriteLine("{0} workplace equipments:\n", company);

            IMouse mouse = workplaceEquipmentFactory.GetMouse();

            Console.WriteLine(mouse);

            ILaptop laptop = workplaceEquipmentFactory.GetLaptop();

            Console.WriteLine(laptop);

            ITablet tablet = workplaceEquipmentFactory.GetTablet();

            Console.WriteLine(tablet);
        }
示例#22
0
 public KeyboardModDecorator(ILaptop laptop) : base(laptop)
 {
 }
示例#23
0
 public HDD(ILaptop Laptop)
     : base(Laptop)
 {
     name  = "HDD";
     price = 100;
 }
 public LaptopDecorator(ILaptop Laptop)
 {
     this.laptop = Laptop;
 }
示例#25
0
 public USB(ILaptop Laptop)
     : base(Laptop)
 {
     name  = "USB hub";
     price = 10;
 }
示例#26
0
 public RAM(ILaptop Laptop)
     : base(Laptop)
 {
     name  = "RAM";
     price = 50;
 }
 public void CreateLaptop(string model)
 {
     _laptop = _factory.CreateLaptop(model);
 }
示例#28
0
 public void SwitchOn(ILaptop obj)
 {
     LaptopAdaptor.ShowModel(obj);
 }
示例#29
0
 //combo box
 private void metroComboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (metroComboBox1.SelectedIndex == 0)
     {
         laptop = new Appel();
         pictureBox1.Image = LaptopStore.Properties.Resources.Apple;
         if (metroToggle1.Checked)
             richTextBox1.Text = laptop.Accept(new DetailedDescription());
         else
             richTextBox1.Text = laptop.Accept(new BriefDescription());
     }
     else if (metroComboBox1.SelectedIndex == 1)
     {
         laptop = new Lenove();
         pictureBox1.Image = LaptopStore.Properties.Resources.Lenovo;
         if (metroToggle1.Checked)
             richTextBox1.Text = laptop.Accept(new DetailedDescription());
         else
             richTextBox1.Text = laptop.Accept(new BriefDescription());
     }
     else if (metroComboBox1.SelectedIndex == 2)
     {
         laptop = new HP();
         pictureBox1.Image = LaptopStore.Properties.Resources.Hp;
         if (metroToggle1.Checked)
             richTextBox1.Text = laptop.Accept(new DetailedDescription());
         else
             richTextBox1.Text = laptop.Accept(new BriefDescription());
     }
 }
示例#30
0
 public PortableLaptopDecorator(ILaptop iLaptop)
 {
     this.iLaptop = iLaptop;
 }
示例#31
0
 public static void ShowModel(ILaptop obj)
 {
     obj.ShowModel();
 }
示例#32
0
 public SoundModDecorator(ILaptop laptop) : base(laptop)
 {
 }
示例#33
0
 public GPU(ILaptop Laptop)
     : base(Laptop)
 {
     name  = "GPU";
     price = 200;
 }