I have a class which contains two integers (a and b) and a reference to an entity.
I want to be able to report back on the sum of all the a's and b's within the class.
E.g. I might have three records:
Entity 1 2 3
a 5 9 3
b 8 1 2
I want my consolidated result for a to be 17, and for b 11.
I'm interested in view on the best approach to this. Now I could sum everything on the fly, but if there are lots of records that might be slow.
Or I could maintain a fake entity which contains the consolidated result and is updated each time any of the other objects are update.
Or I could have a different class for consolidated date?
All thoughts appreciated.
Thanks Chris
I see two ways you might choose from:
a
andb
eagerly, always when any of these changeYou should know which model of the above fits your needs more. I would put the eager way the following way:
The lazy way should go through all created instances of
ABCounter
and sum up the values ofa
andb
.