• Post Reply Bookmark Topic Watch Topic
  • New Topic

Detecting dirty object?  RSS feed

 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class like below:

class P
{
int a;
String b;
List<XYZ> listXYZ;
}

There are several P objects in memory. During an operation, some of them get modified and some remain same as in their earlier state. How can I detect dirty objects at the end of operation? I know I can do that by setting a flag in each setter method, but is there a way to detect dirty objects without that?

regards
Varun
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "get modified"? Does "a" change? Or is the list modified somehow? Or are the elements in the list modified?

You can have a method in this class, something like
public boolean isModified() which will check the change condition and return accordingly.
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "get modified"? Does "a" change? Or is the list modified somehow? Or are the elements in the list modified?


Yes that's right. Anything can change.

You can have a method in this class, something like
public boolean isModified() which will check the change condition and return accordingly.


Yes I know I can do that but I am looking for some simpler solution, something like AOP, but I am not using AOP so any other similar solution.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!