You could isolate all updates to the array in a method, and implement a
special method in the other class like:
Code:
// constructor
public class SomeClass {
private OtherClass otherClass=null;
public SomeClass(OtherClass otherClass) {
this otherClass=otherClass;
}
int [] array;
.
.
.
.
private void setValue(int val, int pos) {
array[pos]=val;
otherClass.listenMethod(int val, int pos);
}
Or you could isolate the array inside a class and supply it with a listener
interface:
Code:
interface ArrayListener {
public void valueChanged(int newVal, int oldVal, int pos);
}
public class BCArray {
public int [] array=null;
ArrayListener arrayListener=null;
public BCArray(int [] array) {
this.array=array;
}
public void setArrayListener (ArrayListener arrayListener) {
this.arrayListener=arrayListener;
}
public void setValue(int val, int pos) {
int oldVal=array[pos];
array[pos]=val;
arrayListener.valueChanged(val,oldVal,pos);
}
}
Either way, the class that changes the array must have a pointer to the
other class, either as an interface or as a plain instance reference.
Bookmarks