Home

Add a comment

 

Re: Choosing a Model/Event Pattern

Jonathan replied on Fri, 2010/03/19 - 10:16am Good article. As Derek said I wish it also discussed an event bus or central event dispatcher with pros and cons. My current project was the first time I was exposed to a central dispatching mechanism. One of the bigger pains for me in past projects using observer pattern was managing and cleaning up listeners. I always had some case where a dead view may still be referenced as a listener on a model or a view may accidentally receive the same event from multiple instances of the same model. Caugh it up to lack of experience or poor design at the time (was just out of college), but so far using a central dispatcher removes much of the pain of doing proper mvc. A subscriber can simply say "I'm interested in these types of events, A, B, and C. I don't care where they come from. When I no longer care about these events, I will unsubscribe myself from the main dispatcher". So there's only one place where a controller is hooked to the dispatcher. With the straight observer pattern, a view may be a listener on multiple models and thus is responsible from removing itself from each object. Now, it hasn't been all roses with our current architecture. For instance, one issue with our app is if you have a windowed application, and inside the window there's a tree. The tree's view fires a TREE_NODE_CLICKED event which goes through the central dispatcher to all subscribers. The problem is the developer intended it to be constrained to that Window (or a single instance of a controller - of which there can be multiple). So while we solved this issue our solution seem less than optimal. I would imagine there's a common design pattern for this. It would be cool if this article was expanded to address this.

Re: Choosing a Model/Event Pattern


Title
Body
HTML : b, strong, i, em, blockquote, br, p, pre, a href="", ul, ol, li, sub, sup
Name
E-mail address
Website
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).