Ejemplo n.º 1
0
 public static Laptop CreateLaptop(Battery battery, LaptopCPU cpu, LaptopDisplay display, Disk disk, LaptopGPU gpu, string manufacturer,
                                   string model, LaptopMotherboard motherboard, double price, RAM ram)
 {
     return(new Laptop(battery, cpu, display, disk, gpu, manufacturer, model, motherboard, price, ram));
 }
Ejemplo n.º 2
0
        public Laptop(Battery battery, LaptopCPU cpu, LaptopDisplay display, Disk drive, LaptopGPU gpu, string manufacturer, string model, LaptopMotherboard motherboard, double price, RAM ram)
        {
            try
            {
                if (battery == null)
                {
                    throw new ArgumentNullException("battery");
                }
                if (cpu == null)
                {
                    throw new ArgumentNullException("cpu");
                }
                if (display == null)
                {
                    throw new ArgumentNullException("display");
                }
                if (drive == null)
                {
                    throw new ArgumentNullException("drive");
                }
                if (gpu == null)
                {
                    throw new ArgumentNullException("gpu");
                }
                if (string.IsNullOrEmpty(manufacturer) || string.IsNullOrWhiteSpace(manufacturer))
                {
                    throw new ArgumentNullException("manufacturer");
                }
                if (string.IsNullOrEmpty(model) || string.IsNullOrWhiteSpace(model))
                {
                    throw new ArgumentNullException("model");
                }
                if (motherboard == null)
                {
                    throw new ArgumentNullException("motherboard");
                }
                if (price < 0)
                {
                    throw new ArgumentException("Laptop price cannot be less than 0. Entered value: " + price);
                }
                if (ram == null)
                {
                    throw new ArgumentNullException("ram");
                }

                _battery      = battery;
                _cpu          = cpu;
                _display      = display;
                _drive        = drive;
                _gpu          = gpu;
                _id           = IDGenerator.NextID();
                _manufacturer = manufacturer;
                _model        = model;
                _motherboard  = motherboard;
                _price        = price;
                _ram          = ram;

                AddToWarehouse(1);
            }
            catch (ArgumentNullException exception)
            {
                throw exception;
            }
            catch (ArgumentException exception)
            {
                throw exception;
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }