Defensive programming guards against programming errors by checking function parameters and preventing invalid objects or states from being created. section 2.3.4
Apply the technique by:
- Representing permitted value types explicitly with a variant. section 2.3.4
- Associating each key with its required datatype. section 2.3.4
- Checking parameter values at runtime before constructing an object. section 2.3.4
Validating book attributes
An Attributes object stores book properties such as YEAR, TITLE, and GENRE. Its constructor verifies that each value matches the key’s required type, rejecting combinations such as a string supplied for YEAR. Searches can then compare valid attribute pairs while treating absent target attributes as don't-care fields. section 2.3.4

