I have a class, which stores an enum
to track if my object is modified, newly created, or no change. If the object is modified, I have additional booleans for each field that is modified.
For instance,
public enum status
{
NoChange,
Created,
Modified
}
private bool? name;
private bool? address;
...
private bool? numberOfDonkeysPurchased;
So the idea is that if the status is modified, then the nullable bools will be either true or false, depending on if these fields are changed.
If the status is not modified, then the nullable bools will be null.
The problem with this is that I have a couple of these fields that I want to check (say 10). Is it valid to create a nullable bool for each field that I am checking, knowing that I maybe be storing a lot of nulls? Or is that not a concern?
Is there a better way to store this?
Thanks!
bool?
each time you add a new property? Or are you using something to auto-generate your code? In the former case, this looks like very painful code to modify... \$\endgroup\$bool?
will need to be added for each new property. \$\endgroup\$NoChange
mean? Has not changed since the last time I looked at it? This is subjective to a consumer. What if you have multiple consumers? Why not just sore the created time and modified time that is associated with every value, and keep track of it that way. You can use a dict for that. Alternatively, borrow some ideas from git or Clojure - make your objects immutable and track every change by storing a new value in a LinkedList along with who made a change and when. That way you can have all of the diffs. There is more than one way to implement this; it depends on usage. \$\endgroup\$