With the design philosophy above, you are often trapped with the hierarchy.
You have this report component (a sub-tree) which must be enhanced to
print differently depending on some external factors. For example
it can print to a printer, a fax or send the report by mail.
There are various way to enhance this report engine:
- Add the functionality to deal with these new requirements
and add a parameter to select the output.
- Turn it into an object. A good solution, but expensive, see
- Play smart with global variable.
- Fiddle with function pointer,
In many cases, you will end up with functions passing around
information needed by sub-functions. For example, the fax and mail
output requires an address, which is behond the scope of the report
module. So if we want to play clean, the report module has to accept
this new parameter, which is totally un-needed for the report itself
so it can pass it down to the output selector which ultimatly will
pass it properly to the output module.