Ejemplo n.º 1
0
        public IDevice CreateDevice(int deviceType, int deviceModel)
        {
            IDevice device;
            DeviceFactoryAbstract factory;

            switch (deviceType)
            {
            case 2:
                factory = new DesktopFactory(deviceModel);
                device  = factory.Device;
                break;

            case 3:
                factory = new MobileFactory(deviceModel);
                device  = factory.Device;
                break;

            case 1:
                factory = new LaptopFactory(deviceModel);
                device  = factory.Device;
                break;

            default:
                factory = new DesktopFactory(deviceModel);
                device  = factory.Device;
                break;
            }
            return(device);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IComputerFactory laptopFactory  = new LaptopFactory();
            IComputerFactory desctopFactory = new DesctopFactory();

            List <IСomputer> сomputers = new List <IСomputer>()
            {
                new Сomputer(laptopFactory),
                new Сomputer(desctopFactory)
            };

            foreach (var сomputer in сomputers)
            {
                сomputer.GetPartsInfo();
                Console.WriteLine(new String('-', 40));
            }

            Console.ReadLine();
        }