Change Tracking of Immutable Objects

Apr 9, 2010 at 12:40 PM

Hi All,

       I have a query. In DDD Entities ideally should be immutable. How do I track changes in an immutable Entity? Say I have a textbox in the UI which is mapped with some property of an Entity. When I load the Page , I set the text of Texbox from the property of the Entity which again gets set from the Data Access Layer (after creation of a new Entity). Now while saving the page I will have to again create a new Entity(since its an immutable Entity) and while creating only i will have to pass the text of Textbox through the constructor. In such a scenario the only solution I can think of is comparing the 2 objects(1 object is the object created while loading and the other is the object created while saving). In such a scenario, is there any other way to track wether that Entity has changed or not?



May 12, 2011 at 6:59 AM


That is the beauty of the INotifiedProperty interface used in conjunction with the MVVM pattern, it automatically sets the property values on your Entities for you.  But, you must use classes that are mutable.  I did run into this with my Address class, since it is a Value object (immutable), what I did was to create a MutableAddress class that has setters as well as getters, and I used this class in my View Models.



Jun 4, 2012 at 8:48 AM


Can you highlight the reason behind keeping the entity immutable in DDD?