I've been looking at MVC implementations and EventBus closely.
I am wondering why not use EventBus instead of Observer Pattern to implement a MVC application?
For example, lets say I have two classes Model
and View
, In typical observer pattern it would be:
public class Model implements Subject { ... }
public class View implements Observer { ... }
Instead, what is the beneft/drawback of an approach using green robot event bus or any other EventBus?
It would be something like:
public class Model {
private int field = 0;
void someFunctionNowTriggerStateChange() {
this.field = field + 1;
...EventBus.getDefault().post(this); //pass itself as the event
}
}
public class View {
@Subscribe onModelUpdated(Model model) {
updateTextLabel(model);
//other model updates
}
}
What are the issues (if any) of using the EventBus to implement MVC vs typical Observer?
Aucun commentaire:
Enregistrer un commentaire