예제 #1
0
    void Start()
    {
        Debug.Log("------------------Command Pattern--------------");
        IElectronicDevice device = TVRemove.GetDevice();

        TurnTVOn     onCommand = new TurnTVOn(device);
        DeviceButton onPressed = new DeviceButton(onCommand);

        onPressed.Press();

        // -----------------------

        TurnTVOff offCommand = new TurnTVOff(device);

        onPressed = new DeviceButton(offCommand);
        onPressed.Press();

        TurnVolumeUp volUpCommand = new TurnVolumeUp(device);

        onPressed = new DeviceButton(volUpCommand);
        onPressed.Press();
        onPressed.Press();
        onPressed.Press();

        TurnVolumeDown volDownCommand = new TurnVolumeDown(device);

        onPressed = new DeviceButton(volDownCommand);
        onPressed.Press();

        // -----------------------
        Television tv    = new Television();
        Radio      radio = new Radio();

        List <IElectronicDevice> allDevices = new List <IElectronicDevice>();

        allDevices.Add(tv);
        allDevices.Add(radio);

        TurnItAllOff turnOffDevices = new TurnItAllOff(allDevices);
        DeviceButton turnThemOff    = new DeviceButton(turnOffDevices);

        turnThemOff.Press();

        // -----------------------
        turnThemOff.PressUndo();
    }
예제 #2
0
        static void Main(string[] args)
        {
            IElectronicDevice newDevice = TVRemote.GetDevice();

            ICommand     onCommand = new TurnTVOn(newDevice);
            DeviceButton onPressed = new DeviceButton(onCommand);

            onPressed.press();

            ICommand offCommand = new TurnTVOff(newDevice);

            onPressed = new DeviceButton(offCommand);
            onPressed.press();

            ICommand volUpCommand = new TurnTVUp(newDevice);

            onPressed = new DeviceButton(volUpCommand);
            onPressed.press();
            onPressed.press();
            onPressed.press();

            ICommand volDownCommand = new TurnTVDown(newDevice);

            onPressed = new DeviceButton(volDownCommand);
            onPressed.press();

            // ---------------------------------- //

            Television theTV    = new Television();
            Radio      theRadio = new Radio();

            List <IElectronicDevice> allDevices = new List <IElectronicDevice>();

            allDevices.Add(theTV);
            allDevices.Add(theRadio);

            TurnItAllOff turnOffDevices = new TurnItAllOff(allDevices);
            DeviceButton turnThemOff    = new DeviceButton(turnOffDevices);

            turnThemOff.press();
        }