我正在使用带有eventbus的Model-View-Presenter设计模式。我有一个演示者,只要有一些信息更新,就会在eventbus中发布一个事件:
public class HomeScreenPresenter extends BaseHomePresenter {
...
...
locationUpdatesManager.getCurrentPlace(place -> {
EventBus.getDefault().post(new OnCurrentPlaceDetailsUpdated(place));
}
);
}
现在,我希望那个地方的细节在其他片段中。所以我所做的就是在这个片段里面这样:
public class PlaceListFragment extends BaseListFragment implements PlaceListView {
protected EventBus eventBus;
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initComponents();
}
@Override
public void onStart() {
super.onStart();
eventBus.register(this);
}
@Override
public void onStop() {
eventBus.unregister(this);
super.onStop();
}
@CallSuper
@Override
protected void initComponents() {
eventBus = EventBus.getDefault();
}
@DebugLog
@Subscribe(threadMode = ThreadMode.MAIN)
public void onCurrentPlaceUpdatedEvent(OnCurrentPlaceDetailsUpdated onCurrentPlaceUpdated) {
//got the event
}
}
在解耦和设计方面是好还是坏? 我应该在演示者中订阅PlaceListFragment
的事件,然后使用PlaceListView
回调片段吗?