I have two views each w开发者_Go百科ith their own presenters and they need a two way communication between them. Like if the user name changes in View A, presenter A needs to notify presenter B of the change and vice versa. Should I create a high level presenter/eventHandler that gets notified when either A or B needs to trigger an event or is there a better way?
Note that the two types of events that is the one triggered from A->B and the one from B->A are different event types.
I believe your views should not communicate directly to each other, rather both should listen to changes in, and propagate changes to, the common model (via the Controller). This is the idea behind the Model-View-Controller pattern. The high level event handler you mention is equivalent to the Controller in the pattern.
Sounds like you could benefit from the Model-View-Presenter framework.
Using the MVP framework with an eventbus will allow your presenters to "talk" to one another. This is a huge topic to go into here and the implementation will depend on you platform. There are lots of open source frameworks fro GWT(MVP4g & GWTP are probably the best options).
Here is a link to a blog post that may point you in the right direction.
http://mvp4g.blogspot.com/2011/04/grouping-multiple-presenters.html
精彩评论