Modular design

Converting a file using a modular Migration on Request tool
The Migration on Request tool follows a simple, modular design. An input module is written for each source format. The module takes the elements and hierarchies of a file and stores them in an intermediate structure. Likewise, an output module is written for each target format. The module takes the elements and hierarchies from the intermediate structure and writes them to a file in the required format. The intermediate structure must be able to adequately represent the features from all the supported formats.
The modular design minimises the amount of code to be written - work on interpreting obsolete formats need only be done once.
The intermediate structure could get large and complicated, but each input module would only produce a subset of the element types and structures, just as each output module would only require (or be able to work with) a subset.
The design allows a new format to be input or output simply by adding a new module to the system. A new input module might introduce element types or attributes into the intermediate structure that are unsupported by the output modules. Similarly, an output module might be written that expects the elements to be of a particular type or structure that some or all of the input modules do not produce. A set of conversion routines are needed to convert between these supported and unsupported features.
Each output module could convert the unsupported information into something that the output format can use. This would not be a good method as it may lead to unnecessary duplication of code (eg. converting a Bezier curve to a series of lines). Instead, the conversion routines are implemented as a separate, centralised process.

Preparing data in the intermediate structure for output
A Support structure is used to store which element types, attributes, features and units are supported by the output module. Before a page is passed to the output module, it is examined for conformity to the criteria in the Support structure. Any elements that do not conform have to be converted into suitable types, or if this is not possible, be removed. Care has to be taken to avoid forming loops, whereby the chain of conversions is never broken. This can be enforced by only converting to 'lower order' element types.
A number of conversion routines exist to transform a particular element type into another. If there is no conversion routine to transform a non-conforming element directly into one that does conform, it may be possible to perform an intermediate conversion to an alternative (unsupported) element type. The process can be applied again and again, creating a chain of conversions - until a conforming element type is reached, or until there are no further options (at which point the element is discarded).
When a new input or output module is added to the system, additional conversion routines should be written to transform any element types that are unsupported by the other modules. Only one conversion routine is required for each new element type - this adds an extra link to the chain of conversions and allows the conversion operations to continue as before. More specialised conversion routines can be written if required, although because the stepped conversions work individually at an element-level basis, this is unlikely to be necessary. The advantage of the system is that new modules can be added quickly and without any modification to any of the other existing modules.
|