Index
Day 9 - Classes
Class organization
-
A class should begin with a list of variables, public static constants should come first; then private static variables followed by private instance variables. There is seldom a good reason to have public variables
-
Public functions should follow the list of variables. We want to put the private utilities called by a public function right after the public function itself
Encapsulation
-
We like to keep our variables and utility functions private but sometimes we need to make them protected so that it can be accessed by a test
Classes should be small
-
With functions we measured size by counting physical lines. With classes we count responsibilities
Single responsibility principle
Cohesion
-
Classes should have a small number of instance variables. In general the more variables a method manipulates the more cohesive that method is to its class
Organizing for change
-
In a clean system we organize our classes so as to reduce the risk of change