7

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?

1
  • 2
    Looks like you are trying to implement CQS (command and query segregation). Commands should never return any data. For queries you have specific query objects. Just rename Command<T> to Query<T> and you're good. Commented Oct 9, 2012 at 15:33

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I thinks introducing CQRS here can cause a lot of confusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.