Basic Design Principles
Model/View/Controller design pattern
- The model is the underlying data structure. It should contain
no GUI code of any sort.
- The view constructs a graphical representation from the model.
- The controller changes the model (and, implicitly, the view)
based on input.
Inspection and Mutation
- An inspector method delivers information about an object without
changing it.
- A mutator method changes an object.
- A mutable class contains mutators.
- An immutable class contains only inspectors.
- Questions:
- Can a single method be both an inspector and a mutator? What would be
the advantages and disadvantages of this?
- Would it ever make sense to create a class without inspectors? Do
most classes need inspectors?
- Under what circumstances would an immutable class be helpful?
Other topics
- Cohesion: Each class and method should do one thing,
and do it well.
- Law of Demeter: Avoid chained method invocations. These can be avoided
by delegating.
- Methods should be written at a single level of abstraction.