Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command Pattern use for Returning Data

I am working on an application and trying to follow Robert C. Martin's SOLID principles. I am using the Command Pattern and I was wondering about the implementation. In all of his examples in Clean Code and Agile Principles, Patterns and Practices in C# his command objects never return anything. His Command interface is;

public interface Command
{
  void Execute();
}

All of the examples are "AddEmployee", "DelEmployee", "EditEmployee", etc. Would I have a command that would be "GetAllEmployees" or is there some other special "Interactor" I would create for that specific purpose? One way I am thinking of handling that specific case is to have two interfaces a non generic like the one above and a generic one like this;

public interface Command<T>
{
  T Execute();
}

What I am asking is would this be an acceptable implementation of this pattern or is there another way we would access data from the application?

like image 366
Lukasz Avatar asked Oct 09 '12 15:10

Lukasz


1 Answers

A command is something that changes state (updates, deletes or additions).

When getting data (and not changing it), you would use a query.

Also see CQS and the related CQRS.

like image 163
Oded Avatar answered Oct 18 '22 18:10

Oded