Introducing Constraints
But what happens if I try to set age to a negative number or a very large number? Maybe I should introduce some constraints on age.
I’ll start by defining some constants for Person, test-first of course.
I get the red squiggly line under MINIMUM_AGE and MAXIMUM_AGE because they haven’t been defined yet. I’ll let Eclipse autogenerate them in the Person class and then I’ll clean them up so they read
| public static final int MINIMUM_AGE = 1; |
| public static final int MAXIMUM_AGE = 200; |
This defines the symbols I’ll use to set the lowest and highest ages I’ll accept to 1 and 200. I’ve never heard of anyone living ...
Get Beyond Legacy Code now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.