80 likes | 187 Views
BTS530: Major Project Planning and Design. Patterns for a Persistence Framework References and Material From: Applying UML and Patterns, 3 rd Edition, chapter 38. Agenda. Pattern: Cache Management Pattern: State Pattern: Virtual Proxy (for lazy materialization). Pattern: Cache Management.
E N D
BTS530: Major Project Planning and Design Patterns for a Persistence Framework References and Material From: Applying UML and Patterns, 3rd Edition, chapter 38
Agenda • Pattern: Cache Management • Pattern: State • Pattern: Virtual Proxy (for lazy materialization)
Pattern: Cache Management • Issue: • Want to maintain materialized objects in a local cache to improve performance (materialization can be slow) and support transaction mgmt operations such as commit.
Pattern: Cache Management • Solution: Cache Management Pattern • Make the database mappers responsible for maintaining its cache. If a different mapper is used for each class, each mapper can maintain its own cache. • Materialized objects are placed in the cache with OID as key. Mapper searches cache first to avoid unnecessary materializations.
Pattern: State • Problem: is there an alternative to conditional logic when an object’s behaviour is dependent on its state. • Solution: State Pattern (GoF) • create state classes for each state (OldDirty, OldClean, etc.), implementing a common interface. • delegate state-dependent operations from the context object to its current state object. • ensure context object always points to a state object reflecting its current state.
Lazy Materialization • Sometimes its best to defer materialization of an object. • e.g. ProductDescription references Manufacturer but only rarely does the latter need to be materialized. • this deferred materialization is known as lazy materialization.
Lazy Materialization • Pattern: Virtual Proxy (GoF) • a “lightweight” version of the “real” object that may or may not be materialized. • the proxy only materializes the real object when it is required.