Java/Encapsulation
From charlesreid1
Encapsulation: public/private.
Deciding what we expose to the outside world, versus what we keep protected, versus what we keep private:
Always make everything as private as possible.
If you find that it's difficult to thoroughly test a class, then the class may be doing too much. Splitting the class up using composition can make the individual units more testable.
A few heuristics:
- Decomposition
- Abstraction
- Subset identification
- Information hiding
- Virtual structuring
- Modularity
- Separating policy and mechanism
- Hierarchy
A few more heuristics:
- Visibility of system status - keep status of things visible to users.
- Match between system and world - keep verbiage and symbols system-oriented.
- User control - allow users ability to leave unwanted state.
- Consistency - maintain consistency across interfaces.
- Error prevention - try and anticipate and prevent errors.
- Recognition, not recall - make things visible, not things they have to retrieve
- Flexibility - things should be flexible across situations
- Accelerators - things unseen by novice users, allow speeding up interaction by expert users.
- Minimal - keep it simple.