dimanche 5 juillet 2020

Command Design Pattern - Execute method with return value

I've implemented Command Design Pattern according to below UML Command

Where Command is is an interface called ICommand:

 public interface ICommand
    {
        CommandType CommandType { get; set; }
        Task  Execute();
    }

It was perfect design until i have been requested to return value from Task Execute(); for specific concrete command, So i thought "OK, lets add a new method Task<T> Execute<T>();" but it means that i need to add empty implementation to all classes that implement ICommand interface (around 10 classes).

I would like that ConcreteCommand will have only one of Execute method, is it possible? Is it must have empty implementation to other method for every ConcreteCommand ? Is there a way to combine those method into one using Task?

Just for clarification, I don't want to have two methods like this:

 public interface ICommand
    {
        CommandType CommandType { get; set; }
        Task  Execute();
        Task<T> Execute<T>();
    }

Thanks!

Aucun commentaire:

Enregistrer un commentaire