Classes and members should be as inaccessible as possible, because this allows us to test components in isolation. A class or member that is not private is part of the API and must be supported forever.
Accessor methods (getters and setters) are better than allowing access to a field directly because you can change the internal representation without changing the API
Rules to make class immutable:
- Make fields private and final
- Don't provide setters
- Prevent class extending (make class final)
- Prevent access to reference of mutable components
Benefits of immutable objects:
- They are thread-safe, require no synchronization
- Can be shared freely
- Great building blocks for other objects