Command Pattern use for Returning Data
c#, design-patterns, solid-principles
Solution
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.
Problem
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?