previous | start | next

## The Importance of Encapsulation

- Even a simple class can benefit from different implementations
- Users are unaware of implementation
- Public instance variables would have blocked improvement
- - Can't just use text editor to replace all

        d.year

    with

        d.getYear()

  - How about

        d.year++?

  -     d = new Day(d.getDay(), d.getMonth(), d.getYear() + 1)

  - Ugh--that gets really inefficient in Julian representation
- Don't use public fields, even for "simple" classes

previous | start | next