Consistency checker
We have a consistency checker class, and an instance of it is injected into the controller. This class is used to check the consistency, but it does not actually perform the check itself. It only controls the different checkers that we provide and invokes them one by one to do the real work.
We require that a consistency checker, such as the one that checks whether the order contains a power cord when a desk-side lamp is ordered, implements the ConsistencyChecker
interface:
package packt.java9.by.example.mybusiness.bulkorder; import ... public interface ConsistencyChecker { boolean isInconsistent(Order order); }
The method isInconsistent
should return true
if the order is inconsistent. It returns false
if it does not know whether the order is inconsistent or not, but from the aspect that the actual checker examines the order, there is no inconsistency. Having several ConsistencyChecker
classes, we have to invoke one after the other until one returns true
or we are...