Implementing CQS

by Colin Adams (modified: 2007 Mar 15)

When I first learned Eiffel, I learned the design pattern for getting results back from commands - storing the result in an attribute of the class being changed. And I dutifully followed it religously.

More recently, I have encountered situations where this pattern seems to be undesirable. If the command can be re-invoked recursively, then things can get tricky.

In these situations, I am increasingly turning to output arguments instead. So I pass a DS_CELL [G] where G is the type of result I am interested in. The pre-conditions for the command include that the cell is non-Void, but the contents is Void. The post-condition (probably) declares the contents of the cell to be non-Void.