At first I called in the ISnapshotService, this is what it does
CountrySnapshot snapshot = snapshotService.CreateSnapshot<Country, CountrySnapshot>(country);
For this to work Country must look like this
public class Country : ISnapshottable<CountrySnapshot>
{
public CountrySnapshot CreateSnapshot(ISnapshotService snapshotService) { }
}
and CountrySnapshot must look like this
public class CountrySnapshot : ISnapshotFor<Country> { }
I used the name "Snapshot" because I initially intended this service to create immutable snapshots of classes for an end-of-period snapshot of a system for accounting purposes. However it has occurred to me that sometimes the result will not be an immutable snapshot, for example a StockL开发者_运维技巧ocation might create a StockAudit (which is not a snapshot.)
So, keeping in mind that this will no longer just create snapshots I need to come up with better names for these 3 interfaces.
- ISnapshotService
- ISnapshottable - Country implements this to indicate it can create a CountrySnapshot
- ISnapshotFor - CountrySnapshot implements this to show it is created from a Country
Any suggestion welcome. Thanks
This is a factory pattern. see http://en.wikipedia.org/wiki/Factory_method_pattern
Seems a lot like memento. Snapshot would be a Memento and Snapshottable would be an Originator that's outsourced its saving capabilities to a SnapshotService.
EDIT: Agreed, this is not memento, although the structure is similar. What it could be is a case of either Temporal Object or - what do you know - Snapshot.
I think it is more like a prototype pattern, because it creates new objects based on the state of an existing object.
I have gone for
- IPrototypeService
- IPrototype
- IPrototypedFrom
精彩评论