Formatter implementation

The structure of formatters mirrors the structure of data elements. At the top is FormatElement. This abstract class is the base class for field formatters and collection formatters. A field formatter handles the formatting of strings for a data field. To handle indexed collections and keyed collections, the formatter hierarchy provides FormatCollection, which is the parent class for keyed collection formatters and the indexed collection formatter. This structure follows the composite design pattern in which collections of formatters can themselves be collections.

The toolkit provides a set of classes that handle a large number of formatting situations. You can easily extend the formatter hierarchy to handle formatting not provided by the toolkit formatters.

For decorators, FormatDecorator is the abstract base class. It introduces the decorated instance variable to identify the formatter for the string that it is to modify. When decorating a string, decorator first calls the formatter's format method and passes the object the format is to convert. The decorator then modifies the string returned by the formatter. When reversing the decoration process, the decorator first removes the decoration and then invokes the formatter's unformat method, passing the undecorated string as a parameter.