Command

14. März 2020

In diesem Entwurfsmuster kapselt das Kommando-Objekt einen Befehl, um es so zu ermöglichen, Operationen in eine Warteschlange zu stellen, Logbucheinträge zu führen und Operationen rückgängig zu machen.

https://de.wikipedia.org/wiki/Kommando_(Entwurfsmuster)
public class Lamp
{
}

public interface ICommand
{
    void Execute();
}

public class PowerOnCommand : ICommand
{
    private readonly Lamp _Lamp;

    public PowerOnCommand(Lamp lamp)
    {
        _Lamp = lamp;
    }

    public void Execute()
    {
    }
}

public class PowerOffCommand : ICommand
{
    private readonly Lamp _Lamp;

    public PowerOffCommand(Lamp lamp)
    {
        _Lamp = lamp;
    }

    public void Execute()
    {
    }
}

class Program
{
    static void Main(string[] args)
    {
        var lamp = new Lamp();

        var powerOnCommand = new PowerOnCommand(lamp);
        powerOnCommand.Execute();
    }
}