Defensive programming validates inputs and guards against programming errors so objects remain valid. Constructors should create only proper objects from their parameter values. section 2.3.4
Apply the technique by:
- Checking parameter values at runtime before constructing an object. section 2.3.4
- Keeping invalid values out of the Attributes object rather than repairing them later. section 2.3.4
Typed book attributes
Attributes.__init__() checks YEAR for int, text fields for str, and categorical fields for the appropriate Enum class. Valid attributes can then support case-insensitive matching and don’t-care search fields.

