previous | start | next

## Don't Supply a Mutator for every Accessor

- `Day` has `getYear`, `getMonth`, `getDate` accessors
- `Day` does not have `setYear`, `setMonth`,`setDate` mutators
- These mutators would not work well
  - Example:

        Day deadline = new Day(2001, 1, 31);
        deadline.setMonth(2); // ERROR
        deadline.setDate(28);

  - Maybe we should call `setDate` first?

        Day deadline = new Day(2001, 2, 28);
        deadline.setDate(31); // ERROR
        deadline.setMonth(3);

- `GregorianCalendar` implements confusing rollover.
  - Silently gets the wrong result instead of error.
- Immutability is useful

previous | start | next