Hidden knowledge is information about required behavior, assumptions, or validity conditions that exists in code but remains unstated in requirements or hidden beyond an interaction boundary. It becomes dangerous when later methods depend on facts that earlier validation never established. section 9.2.4 section 9.6
A cart item that is valid too late
An add-to-cart request validates productId and quantity, then constructs a CartItem while sellerId is still null. The item passes through processing before sellerId is assigned. Because productId and sellerId form the qualified identity, the cart can admit a duplicate. Each method looks reasonable in isolation; the invalid state appears only through their sequence. section 9.2.4
Make hidden knowledge visible by:
- Working backward from invariants instead of assuming that a sequence of setters will preserve them. section 9.6
- Treating validation as a boundary whose exit is guarded by data that proves validity. section 9.6
- Using constructors and data types to prevent incomplete or illegal states from being represented. section 9.6
- Separating parsing from later decisions so partially constructed objects do not silently propagate invalid data. section 9.6
