3 | Encapsulation and Implementation Hiding
programming techniques. However,
as
you will see in this section, there are cer-
tain limitations to the procedural approach that you must overcome to improve
the overall quality of your software designs.
3.1.1 Decomposing Functional Decomposition
Procedural developers typically formulate their program designs using a process
called functional decomposition. This term comes from the mathematics world,
where a mathematical function is broken down into a series of smaller functions
that are easier to understand. From a development perspective, functional
decomposition refers to the process of decomposing a complex program into a
series of smaller modules (or procedures). One common approach for discovering
these procedures is to scan through the verbs used to describe the actions of
a
pro-
gram within the functional requirements. These actions represent the steps a pro-
gram must take to meet its objectives. After all of the steps have been identified,
they must be composed into a main program that is responsible for making sure
that procedures are called in the right order, and so on. The process of organizing
and refining the main program is sometimes called step-wise refinement.
For small- to medium-sized programs, this strategy works pretty well. However,
as programs start to branch out and grow in complexity, the design tends to
become unwieldy as the main program becomes saddled with too many respon-
sibilities. Much of this burden stems from the fact that the main program must be
accountable for all of the data used by the various procedures.
Ideally, you want to be able to delegate some of these management duties to pro-
cedures, but for that to happen, the procedures need to be smart enough to figure
certain things out on their own — and that requires data. Of course, a main pro-
gram can pass instructions to a procedure via parameters, but the downside to
this approach is that cluttering up a procedure's parameter interface causes it to
be tightly coupled to the calling program that provides the data. These kinds of
dependencies cause all kinds of maintenance problems and also make it much
more difficult to reuse the procedures in other environments. On the other hand,
liberal use of
global
data within procedures is also dangerous. For example, think
about a program that has a series of procedures that all share and manipulate a
piece of global data. If you arc asked to change the sequence of the procedure
calls,
can
you be certain that this change will not result in some kind of unpredict-
able data corruption scenario?
90