Maintenance and Extensibility Planning | 59
interacting with new elements in the application. In any case, it doesn’t lend itself to
a flexible site, and we should rethink it.
Adding Extensibility to a Plan with Granularity
The plan using The Big Function, even though it has limited flexibility, is bound to
break down and fail in the long run. To avoid getting stuck with an inalterable appli-
cation, you need to consider some granularity in your design. In this contextgranu-
larityrefers to the amount of functionality each of your classes has. The trade-off
between full functionality and granularity is that the more functionality a class has,
the more it will do all by itself. After all, most classes we create are developed to add
the functionality of several built-in classes. However, sometimes less is better. The
less functionality a class has, the more components in your application its functional-
ity can employ. Figure 1-10 shows how this granularity might work.
The Big Function from the last section has been broken down into three smaller
(more granular) functions. Using composition, the functionality of the Big Function
is duplicated. However, the granularity gives the developer far more options in the
future. In the context of developing a real-world application, your design mustlook
over the horizon. That is, you need to plan for both possible and unknown changes.
Figure 1-10. Granular functions
Product
Product composer
function LI(p)
{
load image
}
Loads image
function LT(p)
{
load text
}
Loads text
function LM(p)
{
load image
}
Loads menu
function LF(p)
{
load flv
}
Loads video
Service
Service composer
Stream video
Video composer
X requirements
X composer