Validation checks requested values or state changes against validity constraints, preventing unexpected errors and helping systems handle invalid input gracefully. Define the consequences of invalid data instead of leaving clients to discover them through failures. section 3.2
Keep validation close to the behavior that protects consistency, while moving genuinely complex checks outward:
- Let the class containing the data enforce its own consistency whenever the required information is available locally. section 3.1.1
- Encapsulate operations requiring database information or complex business rules in a service or dedicated validation class. section 3.1.2 section 3.7
- Avoid setters for attributes whose changes require consistency checks; expose meaningful operations that perform the checks safely. section 3.4.2
- Choose between explicitly defining method preconditions and postconditions and validating input from a business perspective. section 3.2
Protecting an offering
An Offering should reject enrollment when its participant limit is reached and reduce its available seats when enrollment succeeds. Clients should call an enrollment operation rather than modify a participant collection or seat count through unrestricted access. If deciding whether enrollment is valid requires database information, an accompanying service should encapsulate the complete operation and its checks. section 3.1.1 section 3.1.2
Use the entity-consistency diagram to see how validation remains with the data-owning class when local rules are sufficient. section 3.1.1





























