Pattern for handling Object Deltas

Started by
2 comments, last by Jedi_Dude 23 years, 1 month ago
Let me briefly describe my situation: I am working on a system with a number of dynamic objects. (In this case, I''ll use the example of Cat.) First of all, a base cat object is created. This might include things such as the cats name, color at time of birth, a picture, etc.. Then at certain user defined times, events occur in the cat''s life. An event is simply changing one of the attributes of the Cat. For example, after 2 years, the cat might now be 15 lbs instead of 10 lbs. On the screen where the object information is displayed, the user has a control where they can change the current date. Based on their selection, the object is created using all of the events that apply to the object as of that date. As there can be many events in the objects life, I had thought that the best way to handle this would be to store all of the object deltas with the base object, and then just apply them as needed. My question is: Is there an existing pattern that will handle this? I''ve looked and haven''t found anything right away. If you know of an existing pattern can you please point me in the right direction? Thanks!
Advertisement
I;m not real sure what problem you want a DP for - if you have an object that handles the events (CWorld or the like) then you need a IWorldObserver abstract base class, which CCat will inherient from. IWorldObserver should have a method along the lines of EventNotification(...) and CWorld should have two methods, AddObserver & RemoveObserver.

That''s the OOD version of callback functions.

Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I don''t have the DP text on me, but it seems to me there was a "Command" pattern. An example was given in the context of a word processor, where each action from the user was a Command that modified the document. The document was always stored in the latest state, but a list of N commands was kept in memory. Each Command had a function to modify the document, and optionally, to undo its modification. In this way, the Commands can be used to implement Undo (step backward through command list) and Redo (step forward).

This sounds to me like what you''re describing. Your Commands are actions that modify the given game object. Command might not be the right DP, since I''m reciting this from memory, but the example stuck with me so I''m pretty sure that''s right.
That sounds right! It should be enough to get me started at the least. I''ll do more research on that. Thanks!

This topic is closed to new replies.

Advertisement