Problems with the OOP

Hi everyone in the forum,

I posted several months ago a question about what some of you helped a lot to understand about interfaces. Now my problem or question is that i have no idea by using the interfaces and events how to implement this:

i have a logical class in whih several String [] are kept. i am trying to send a message to the interface when some values of this arrays change (actually when they are updated) to actualize the screen (a couple of tables). Now the way i am doing it allows me to send that something in the logical has changed but not what exactly has changed. How can it be done using the interface and events?

Many thanks

private Vector<LogicalDataChangeListener> logicalListeners =new Vector<LogicalDataChangeListener>();

publicvoid addLogicalDataChangeListener(LogicalDataChangeListener l){

if (logicalListeners.contains(l)){

return;

}

logicalListeners.add(l);

}

publicvoid removeLogicalDataChangeListener(LogicalDataChangeListener l){

logicalListeners.remove(l);

}

protectedvoid fireLogicalDataChangeListneners(){

Vector tl;

synchronized (this){

tl = (Vector) logicalListeners.clone();

}

if (logicalListeners.size() == 0){

return;

}

LogicalDataChangeEvent event =new LogicalDataChangeEvent(this);

for(int i= 0; i< logicalListeners.size();i++){

LogicalDataChangeListener listener = (LogicalDataChangeListener)tl.elementAt(i);

listener.dataHasChanged(event);

}

}

[2540 byte] By [patucosa] at [2007-10-3 2:51:00]
# 1

I think either your LogicalChangeEvent needs to carry what has changed so the listener can retrieve that information and respond accordingly, or your dataHasChanged method needs another argument that specifies what changed. Either way, your interface is responsible for notifying listeners when data changed, so it should be responsible for telling them what changed too.

As a side note, if you declare t1 as Vector<LogicalDataChangeListener> then you won't need to cast anything.

BinaryDigita at 2007-7-14 20:39:51 > top of Java-index,Desktop,Core GUI APIs...
# 2
How can it be done? i didn磘 know how or even that the event could transmit what has changed as parameter :?
patucosa at 2007-7-14 20:39:51 > top of Java-index,Desktop,Core GUI APIs...
# 3

LogicalDataChangeEvent is a class you created right? You can add to it any information your listeners will need. When you create the event and notify the listeners, you should know at that time what was changed, so just specify that for the listeners. Depending on what you need, you can either include that information in the LogicalDataChangeEvent class, or as a 2nd argument to the dataHasChanged method. Either way, some part of your code knows which array element was changed and that information needs to be propogated to your listeners somehow.

BinaryDigita at 2007-7-14 20:39:51 > top of Java-index,Desktop,Core GUI APIs...