> The number of occupants of a room must be positiv and a child must be accompanied by at least one adult. My type Occupants has a constructor Occupants(int adults, int children) that varifies that condition on construction (and also some maximum values).
Or, you could do what I did when faced with a similar problem - I put in a PostgreSQL constraint.
Now, no matter which application, now or in the future, attempts to store this invalid combination, it will fail to store it.
Doing it in code is just asking for future errors when some other application inserts records into the same DB.
Or, you could do what I did when faced with a similar problem - I put in a PostgreSQL constraint.
Now, no matter which application, now or in the future, attempts to store this invalid combination, it will fail to store it.
Doing it in code is just asking for future errors when some other application inserts records into the same DB.
Business constraints should go into the database.