Design Patterns in the VCL -- DFM as Memento
Revealing the Magician's Secrets
- Component Palette ==> Prototype
- Panel ==> Composite
- .DFM file ==> Memento
- Problem
- How do I externalize the state of a class (e.g., for persistence,
streaming, or recovery) without violating its encapsulation of
private implementation details?
- Solution
- Memento suggests creating an "opaque" external representation for
this encapsulated state, readable and writable only by the class
which creates it.
- Consequences
-
- Because the Memento is opaque to the client, the creator class
can safely externalize its state to the Memento, and hand
it off to the client, without exposing the client to any
encapsulated implementation details.
- Other objects can "hold" the Memento for the creator (or by extension, persist it in binary format), and return it to the creator on demand.
- Because the Memento is opaque to the client, the creator class
can safely externalize its state to the Memento, and hand
it off to the client, without exposing the client to any
encapsulated implementation details.