Here’s a good pattern to use when you have a domain object that combines non-varying and time-varying data. Perrin’s modified the original pattern to use generics: a good choice. (Why is it a good choice? Because objects that combine these two types of data are usually conceived of in a direct-but-composed way: we don’t think of a Product as changing it’s identity because it is or is not on sale, but we do think of a Product and its normal- or sales-price as a combination of two things. While it’s easily possible to express this type of structure using inheritance, making them parameters to a generic is a batter match with the conceptual model.)
Here’s a challenge (for explicitly typed languages: for those with duck-typing it’s trivial):
Design a Snapshot<T> such that you can query any property P in T for a given time. For instance, if you had Snapshot<PlayStation3> myPlayStation, you could query it’s price using code similar to this form:
Price p = myPlayStation.ValueAt(myDateTime).Price()
Hint: Would the problem be easier (or possible) if you were to use a CTP?