concept Specification object in category php

appears as: Specification objects, Specification object
PHP in Action: Objects, Design, Agility

This is an excerpt from Manning's book PHP in Action: Objects, Design, Agility.

Now we can implement a single validator class (see listing 17.14) that can be responsible for any kind of validation, since the actual validity checking is farmed out to a Specification object.

Listing 17.14. The validator is independent of what kind of validation is performed
The responsibility of the validator itself is to talk back; to report to the coordinator what’s OK and what isn’t. In the constructor, we supply it with an error message that it can use for that purpose. It also needs the Specification object that encapsulates the nature of the check being performed.
If the Specification object is satisfied, the validator uses setClean() to report that fact to the coordinator. The coordinator then copies the value to the CleanRequest object. Returning TRUE is not strictly necessary in the context, but it’s logical.
If the Specification object is not satisfied, the validator adds the error message to the coordinator’s error list.