XML Flyweight DP

  

(Adopted from: Design Patterns in XML Applications by Fabio Arciniegas A).

Example: Read a file and create a collection of CD objects:

All the information about the artist may be factored out into a flyweight:

a fine-grained object that encapsulates information (usually immutable) shared by many other objects.






Use SAX handler:

Whenever a CD open tag is found, create a new CD object.
Whenever title or year elements are found, enter them in the current CD.
Whenever an artist element is found, ask the artist factory to create it.