示例#1
0
        public void DesignRoom()
        {
            var simpleSwitchFarWall             = new SimpleSwitch();
            IElectricalApplicanceService lightA = new LightFixture();
            IElectricalApplicanceService lightB = new LightFixture();
            IElectricalApplicanceService fanA   = new CeilingFanFixture();

            simpleSwitchFarWall.ElectricalApplianceService = lightA;
            simpleSwitchFarWall.ElectricalApplianceService.TurnOn();
            simpleSwitchFarWall.On();
            simpleSwitchFarWall.ElectricalApplianceService.TurnOff();
            simpleSwitchFarWall.Off();

            var simpleSwitchNearWall = new SimpleSwitch();

            simpleSwitchNearWall.ElectricalApplianceService = lightB;
            simpleSwitchNearWall.ElectricalApplianceService.TurnOn();
            simpleSwitchNearWall.On();


            var fancySwitchNearWall = new FancySwitch();

            fancySwitchNearWall.ElectricalApplianceService = fanA;
            fancySwitchNearWall.ElectricalApplianceService.TurnOn();
            fancySwitchNearWall.On();
        }
示例#2
0
        public Client()
        {
            IElectricalEquipment fan   = new Fan();
            IElectricalEquipment light = new Light();

            var fancySwitch = new FancySwitch();

            fancySwitch.Equipment = fan;
            fancySwitch.On();
            fancySwitch.Off();  //turn off fan

            fancySwitch.Equipment = light;
            fancySwitch.On();
            fancySwitch.Off(); //turn off light

            var simpleSwitch = new SimpleSwitch();

            simpleSwitch.Equipment = light;
            simpleSwitch.On(); // turn light on
        }