Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Message is one thing. A container of data.</p> <p>Validation is a <em>separate</em> thing. Validation is separate from the Message because validation depends on non-Message data. Validation includes one or more algorithms that establishes if a valid Message could be built from some data.</p> <p>You want Messages to be built <strong>only</strong> when they're valid. You want all of the the methods of a message to require and depend on validity. That gives you easy-to-understand responsibility.</p> <p>Therefore, a Message should not contain any validation logic. That logic lives just outside the boundaries of a valid Message. It's part of a <code>MessageFactory</code> or <code>MessageValiadtor</code> that determines if some given puddle of data could be used to build a valid Message.</p> <p>You have two things: <code>MessageValidator</code> (or <code>MessageFactory</code>) and <code>Message</code>.</p> <p>There is no <code>isValid</code> in a Message. It must be valid or it would not exist.</p> <p>MessageValidator builds Messages from source data. If it cannot build a message can can throw an exception. It should also accumulate the list of errors it finds so it can be interrogated to determine what the various problems were.</p> <p>Consider the possible mutations: Multiple variant subclasses of Message. The Validator may identify a specific subclass. No application changes are required to implement this.</p> <p>Multiple Validators for special situations, exceptions, extensions, etc. It's just a subclass of MessageValidator with the same interface all validators have and emits an instance of Message (or one of it's subclasses.)</p> <p>Since the validation rules are separate from a valid message, the Validator can provide different assumed defaults or derived data, also.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload