Notification Pattern

A Notification collects errors so that all problems which led the failure of a routine can be reported at once, as apposed to an Exception which only reports the first error. This pattern assumes that it's possible to continue the routine and find more issues.

This pattern is intended for reporting errors with the inputs to a routine. If the routine failed due to a network issue, for instance, throwing an Exception telling the caller what happened is enough. The call failed, but it was not an issue with how the caller treated the routine, and so it doesn't need further elaboration. If the caller passed in multiple arguments, however, and several of the arguments were distinctly invalid, reporting all of the invalidities on the first call can save the caller time.

This pattern also assumes that the caller can do something to fix the issues. This usually means that the notification errors will be shown to a human at some point. The call might have come from a user interface, where the errors can be shown immediately, or the caller could log the notification errors to a database, where a developer will see them eventually.

#software #pattern