Next: Isolating the Symbol Up: Design

Modularity Principle

Unrelated parts of the system should be separated, and related parts of the system should be grouped together. Access to a grouped component should be through a simple interface; normally a small group of functions, each with a few parameters. We say that the details of a component are hidden by the interface. Why do we design this way?

This principle can be applied to deciding what code goes in a function, when to define a class, or what files to put classes and functions.

The basic process can be defined as identifying the design decisions in the code that may change in the future. A design decision is a choice in how to implement something, such as a choice to implement a list with a linked-list or to represent scoping with a stack. For each design decision that is deemed likely to change and to be costly to change, a module can be created to hide that design decision. Consequently, clients of the code access the module interface rather than the design decision directly. When the design decision changes (and the interface stays the same), the client is effectively protected from the change.


William Griswold
Sun Dec 31 18:26:15 PST 1995