can ne 1 answer this interesting question?

Hi!

if a data member in an instance of a class gets its value changed through an accessor method, how can i track that event and get the information about the change made from another class? does java provide ne inbuilt methods for this?

for example, i have an instance of a 'Person' class whose general structure is as follows.

class Person

{

// --

// --

// definitions of other data members.

String FirstName;

public void setFirstName(String s) // accessor method.

{

FirstName = s;

}

// -

// -

// definitions of other accessor methods.

}

now if i want to track any changes made to 'FirstName' from other class, say class 'SenderParty', how can i do that WITHOUT MAKING NE CHANGES TO THE CLASS 'Person' ?

-Vai.

[857 byte] By [v_sanas] at [2007-9-26 22:07:47]
# 1

as far as i know of , you have to make changes to that particular class.

Here might be a round about way. Create another class which has class person. Then allow changes to the firstname through this class and keep track of it.

I am giving this suggestion based on the assumption that the Person Class is a third party class whose implementation you dont have a handle on or you dont have rights to change it.

Hope this helps.

SriniNathan at 2007-7-4 1:24:05 > top of Java-index,Other Topics,Java Community Process (JCP) Program...
# 2

// you can include static boolean variables for each data member that you want to track

for example, you can add

public static boolean booFirstNameChanged = false;

at top of class Person. Once the setFirstName(String s)

method is called you can set [code]booFirstNameChanged = true.[\code]. This will set the first name flag for all classes since you declared it as static (one instance for all classes creted). If flag is true, you know it has been changed by a class.

...

Person me = new Person();

me.setFirstName("Justin");

// at this point, booFirstNameChanged will be set to true

Person you = new Person();

you.setFirstName("Tony");

...

hope this helps some,

jmschrei

jmschrei at 2007-7-4 1:24:05 > top of Java-index,Other Topics,Java Community Process (JCP) Program...