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, in case there is one (the return value of the method).
- [Optional] Access the cause of the failure, in case 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 go even further, such as returning the severity of a failure or adding any other relevant information for the specific use case. The success indicator could be binary (true
or false
), or there could be more than two states, such as success, partial success, and failure. Your imagination (and your needs) is your limit...