The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Tracking Modifications of objects

Hi there,

Just wanted to know from everyone out there what they do to track the modifications to an object, do they user arrays to store which properties have changed, do they clone the object and do a compare when writing back ?

I really cant see the best way to do this !

Thx for your time.
Andy Send private email
Wednesday, October 10, 2007
Why do you want to track modifications? What's the broader problem that you're trying to solve?
Wednesday, October 10, 2007
Updating a user for example, I am trying to establish if people update all of the user data everytime or if they update only what has changed.  If they update only the changed data, how do they do it ?

There are a number of ways, a modification flag for each property of the object, a clone of the object (which would require some logic to establish what has changed) or a list of items stored in the object that has changed

I'm just trying to establish what people do normally.

in the data layer we have 2 systems that we need to write to.  Some of the user data goes to one, some goes to the other, I didnt want to write to both systems everytime, i wanted to only write to them if necessary.  We have one data transfer object that stores all of the user data which gets passed to the datalayer so I would like to keep a track on what has changed in this object and only write if necessary.
Andy Send private email
Wednesday, October 10, 2007
I would say it depends on the language.

In python for example, I would use a dictionary - created on the fly using introspection.

In plain C, just use a bitmap.

In C++, make the object properties objects themselves which are all derived from a base class with a bool m_bDirty member. Then whenever the property is set (using operator overloading) you can set the m_bDirty member to true and check that later before writing to the database.
Wednesday, October 10, 2007
For .Net, you may want to take a look at Rockford Lhotka's CSLA framework.  This handles the problem you indicated, plus some other common problems w/ business objects.

A simpler solution might be to use ADO.Net datasets to track rows that have changed.

I believe many ORM's also track which objects have changed so they can update only the rows that have changed.
D. Lambert Send private email
Wednesday, October 10, 2007

You can look at this problem from a slightly different perspective: treat the modification of a property as a command (typically created somewhere in the UI). This allows you to explicitly keep track of what changed and undo the changes easily. Object representing property modification could, for instance, contain a reference to the modified object and two values of the property: before and after the modification.

I am not entirely sure if this is a simple solution for your scenario, but I found this approach useful a couple of times.

Best regards!
Marcin Hoppe Send private email
Friday, October 12, 2007
In my custom ORM framework I use typed DataRows and I think it's a good solution.
Albert Send private email
Saturday, October 13, 2007
Thanks Everyone,

you've given me a few ideas here.  csla sounds interesting. 

thanks again,

Tuesday, October 16, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz