Say I have a collection of items, for example a List<Item>
, and I need to check if any of the items is modified from a wrapper class, for example, a value of any of an item's propery is changed through a setter:
List<Item> items = itemsWrapper.getItems(); // itemsWrapper contains a list of items
Item anItem = items.get(index);
item.setProperty(property);
itemsWrapper.hasChanged(); // ??????
I am trying to figure out a way of achieving the last statement, or something similar.
I can see there are similar questions, like this one where using Hibernate is suggested but the answer is very vague, and my question is not DB related. It also mentions setting up a list of listeners, but I am not sure howt his could be done.
Or this other question, where the chosen answer suggests using a dirty
flag that you need to rise every time you modify a property. However, my class would actually get dirtier, paradoxically, and I would need to modify dozens of methods that modify item's properties.
Is there another approach, best if it's transparent?