From charlesreid1

Revision as of 18:31, 18 June 2017 by Admin (talk | contribs)

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.

Java

Encapsulation happens with fields or with members in Java. You can make fields and members private, protected, or public. By default, methods and fields of a class are private.

Private means only instances of this class can access this method. No one else will be able to see the interface - not even child classes.

Protected means instances of this class, as well as instances of child classes, can see the interface - but no one else can see it.

Public means anyone who wants can walk up and do whatever they would like with your variable.


Junk

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.