The Operation Result pattern
The Operation Result design pattern can be very simple to more complex. In this section, we explore multiple ways to use that pattern. We start with its simplest form and build on that until we can return messages, values, and add severity levels as the result of an operation.
Goal
The role of the Operation Result pattern is to give an operation (a method) the possibility to return a complex result (an object), which allows the consumer to:
- [Mandatory] Access the success indicator of the operation (that is, whether the operation succeeded or not).
- [Optional] Access the result of the operation if there is one (the return value of the method).
- [Optional] Access the cause of the failure if the operation was not successful (error messages).
- [Optional] Access other information that documents the operation’s result. This could be as simple as a list of messages or as complex as multiple properties.
This can...