lundi 11 juillet 2016

Decouple command from its handler

My command and handler is in two different layers. I want to my command be as a POCO and know nothing about its handler. The solution that came in my mind is something like this:

public interface ICommand
{
    string GetHandler();
}

public interface ICommandHandler
{
    void HandleCommand(ICommand command);
}

public class XCommand : ICommand
{
    //...
    public string GetHandler()
    {
        return "xh";
    }
}

[Handler("xh")]
public class XCommandHandler : ICommandHandler
{
    public void HandleCommand(ICommand command)
    {
        //handle
    }
}

Is this a command pattern?

Aucun commentaire:

Enregistrer un commentaire