Observerパターンに問題があります。
まず、サーバーからデータを取得するためのHttpHelperクラスがあり、これをObserverableとして使用しました。
public class HttpHelper extends Observable,Runnable{
public void run(){
//do long task to get data
String result = getData();
setChanged();
notifyObservers(result);
}
}
DataManagerクラスは、完了するとHttpHerlperからデータを取得し、ビジネスタスクを実行します。
public class DataManager implements Observer {
public void doTask(){
HttpHelper helper = new HttpHelper();
helper.addObserver(this);
Thread thread = new Thread(helper);
thread.start();
}
public void update(Observable obj, Object data) {
if (data instanceof String) {
// do some stuff with this data
// Then I want to notify the result to the view
Model model = doSomething(data);
notify(model)
}
}
}
最後に、Viewクラスは、DataManagerがタスクを完了するとデータを更新します。
public class View{
private void getData(){
DataManager manager = new DataManager()
manager.doTask();
}
public void update(Observable obj, Object data) {
}
}
オブザーバーをもう一度使用する必要がありますか?そして、どうすればそれを行うことができますか?
P / s:何らかの理由で、HttpHelperとDataManagerを分離する必要があります。
更新:クラス構造は次のとおりです
https://www.dropbox.com/s/givn6vzvqr4cgye/bkd.png