Quantcast
Channel: Field wrappers for tracking and applying changes to database fields - Code Review Stack Exchange
Viewing all articles
Browse latest Browse all 2

Answer by t3chb0t for Field wrappers for tracking and applying changes to database fields

$
0
0

Using the Editable<T> for wrapping the repetitive code was a good idea. I would however change a few things.

  • I'd named it ChangeTracker as it better describes its purpose.
  • I'd named the Changed property to IsDirty. Changed sounds more like an event.
  • I'd named the _getSource field _getSourceValue.
  • Since you are interested in equality and not sorting, you should use the EqualityComparer<TValue>.Default instead.
  • This type does not have to be disposable. There are no resources to be freed and just setting all properties to some values on dispose is meaningless.
private IEditable[] _fields;private IEditable[] Fields

Having both a private field and a property is unnecessary.


ContactModel2 has become much smaller but it's still to large. The entire database code shouldn't be there. It belongs to a different layer.


RecordEditable - Same as above, it should be a different abstraction layer - not a part of the model and it also does not have to be disposable because it does not free any resources.


You might consider making the properties of the Contact virtual and override them in a new derived type like class ContactWithChangeTracking : Contact. This way you could still use the same old type as before but with additional abilities.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>