Can a class observe multiple observables?
If a Class that is Implementing Observer can Observe multiple Observable
Classes, how will the class know which Observable class has changed?
public class MainActivity extends Activity implements Observer {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ObservableClass1 oc1 = new ObservableClass1();
oc1.addObserver(this);
ObservableClass2 oc2 = new ObservableClass2();
oc2.addObserver(this);
}
@Override
public void update(Observable observable, Object data) {
//How will I know which observable hasChanged?
}
}
I couldn't find any method on the observable to compare or know its class
name.
Or should I use
observable.getClass().getSimpleName();
and make a String comparison?
No comments:
Post a Comment