We are designing a new component and considering using the command design pattern.
We have two main type of commands that will implement our IOurCommand
interface (from which other Commands will inherit).
The issue is that the first command CommandDoUpdates
does not need to return any value, while the second command CommandGetData
is to fetch data, so it needs to return a List
of some objects( List<DataRow>
)
Things we are considering to deal with the situation:
- Return a Class that will contain an indication about the success of the operation (bonus) and a List of objects that will be an empty list for all the
CommandDoUpdates
. - Keep the
List
as a member of the concrete command - Potential solution, but makes our life harder for other reasons (shallow copy Vs. Deep copy and so). - Same as #1, but return a base class in the function, and every calling calss will have to down cast the result to the concrete class (Down cast is not a good practice since the client will need to know what is the actual return value).
- Splinting the command to two different hierarchies (one that returns a value and one that does not), and using two different Receivers - I really don't like it, but it's an option.
This post is good reading about whether a command should return a value/status or not. This is relevant since in the GoF book the Command design pattern does not return a value.
My actual questions are:
- Can you think of a better solution?
- Any pros or cons for options 1,2 and 3, any pros for option 4?
Thanks!
>`