A Collection of History Patterns

By: F. Anderson
Published in: PLoPD4
Pages: 263-297
Category: Time

Summary: Record an object's history by associating the state with the event that caused it.

Pattern: Edition

Pages: 267-270

An event causes an object to change the value of a variable. Audit information must be attached to the new value recording the time of the change and the responsible user. To represent the relationship between the new state and the event, use Memento [Gamma+95] and capture the relationship by an edition, which provides the association between the event and the state.

Category: Reactive and Real-Time Systems, Time

Pattern: Change Log

Pages: 271-276

The value of a simple variable has changed. The previous value is to be recorded for audit purposes. To store the previous value and keep the previous state accessible, assign a change log to those objects whose simple variables will be tracked over time.

Pattern: History on Association

Pages: 276-280

The value of a variable that references a complex object has changed. The previous value is recorded for audit purposes. To maintain the historical values of a complex variable, replace the pointer to the complex object with an instance of history. When the value of the variable is changed, a new edition is added to the history.

Pattern: Posting

Pages: 280-285

The value of an accumulated total has been changed via the posting of a transaction. The amounts that contribute to the total should be recorded for audit purposes. To record the contribution of each transaction to the total, resolve the many-to-many relationship between account and transaction with a posting subtype of edition. This provides a historical wrapper around the transaction.

Category: Time, Transaction Processing

Pattern: History on Self

Pages: 285-289

To associate all the changes of state that may have occurred on an object as the result of a single event, instead of applying history to individual variables, apply it to the object as a whole. Before changing any state as a result of a single event, a new edition is written to history.

Category: Reactive and Real-Time Systems, Time

Pattern: Memento Child

Pages: 289-293

A member has changed containers. To remove an object from a collection, yet retain the reference, use History on Self before changing the originator's parent. Replace the originator with the memento in the memento's container. After a predetermined duration, remove mementos from the children of the container.

Pattern: History on Tree

Pages: 293-296

For some major business transactions, you must treat a component as the sum of its parts and create a snapshot of an entire collection of nodes. To implement this treatment of the whole, recursively apply it to the descendants of the subject node.