previous | start | next

## Designing a `Day` Class

- `daysFrom` computes number of days between two days:

      int n = today.daysFrom(birthday);

- `addDays` computes a day that is some days away from a given day:

      Day later = today.addDays(999);

- Mathematical relationship:

      d.addDays(n).daysFrom(d) == n
      d1.addDays(d2.daysFrom(d1)) == d2

- Clearer when written with "overloaded operators":

      (d + n) - d == n
      d1 + (d2 - d1) == d2

- Constructor `Date(int year, int month, int date)`
- `getYear`, `getMonth`, `getDate` acccesors

previous | start | next