Read the description of the Builder Pattern
in the Design Patterns book. This should do
what you want.
Basically:
- Each Matrix HAS-A CellRenderer (the Builder object)
- There is an abstract CellRenderer class that defines
the interface: render_scalar(), render_link(), render_percentage() ...
- Concrete CellRenderer classes like HTMLCellRenderer,
ExcelCellRenderer, etc., implement the interface of
the CellRenderer class.
- Now you can configure a Matrix with a CellRenderer
for the appropriate output type.
- The Matrix knows which of the CellRenderer interface
operations to call for which type of cell item (switch statement).
Alternatively, and much cooler, you can solve this problem
in the CLOS (Common Lisp Object System) way by using
Damian Conway's module Class::Multimethod. This
module allows you to have dynamic dispatching based on
the type of multiple arguments.
Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com