Here are four prime directives you should strive to support:
-
No Surprises:
The behaviors of Instances of a class should be consistent with its model, defined by its class and member names.
Streams should manage sequences of thingsBehaviors should be repeatable and correct. Its public interface should describe what it does in a way that any competent developer can understand.
Lists should insert, delete, enumerate, access, and modify list items. -
Maximize Cohesion:
Things that are grouped together into classes and packages should be related in function and be focused on a single objective. -
Minimize Coupling:
When a component changes, everything that couples to it may need to change. Try to couple only to public interfaces, not implementations. Try to minimize “assumption” coupling and “need to know” coupling as well as object and data coupling. -
Keep it Small and Simple:
The systems we, as developers work on, are often extremely complex. The only way we can manage that complexity is to partition the system into small and simple parts, called packages. Our goals should be to make each package understandable in an hour or so, and so simple there are obviously no deficiencies.In well designed code the syntax and semantics of the public interface of classes and packages is much smaller than their implementations. So we especially strive to make the public interface of each class small and simple. We do that by making each class and package focus on a single activity or a few intimately related set of activities. We say that such classes and packages are cohesive. Since most professional and some academic software implementations are too complex for one person to understand completely, it becomes very important to hide as much as possible of the complexity of the implementation behind simple interfaces. But that only works if clients of that software can use it reliably without knowledge of those details.The C++ standard library is a good example of this. Most of the library can be used knowing only its interfaces.
Conclusions for Prime Directives:
Fundamental things you should always strive to do:
-
No Surprises:
Make your classes and packages do what their text says they do. Make operations repeatable. Try to remove all latent errors. -
Maximize Cohesion:
Focus each class and package on a single activity or small set of intimately related activities. -
Minimize Coupling:
Pass as few arguments as possible; pass by value or constant reference; try not to return pointers. -
Keep it Small and Simple:
Make functions fit on one page, try to keep number of public functions less than a dozen per package, make public interface describe service provided without disclosing implementation detail.