|
|
|
|
|
by mandeepj
4143 days ago
|
|
> Basically, you can pass around a live-binding object and changes made to it in one module are immediately reflected in another. This can work pretty good up to certain level but after that this can go out of hand pretty quickly. The cascading effect will become hard to debug. > Whereas with a pub/sub model, you publish messages out to a hub and it is up to the module to decide how to react to the message. At least it is at one place to modify and debug. This is loosely coupled. You can easily decide how to react based upon messages. Very easy to introduce new workflows or use cases. > We have a global live-bound object that holds the session data. Looks like you are sitting on something that is waiting to explode soon. Global objects are evil |
|
Totally agree, we recognized this before we began using them. They are used for common elements between modules, and we don't hold a lot of data with them.
>At least it is at one place to modify and debug. This is loosely coupled. You can easily decide how to react based upon messages. Very easy to introduce new workflows or use cases.
Maybe. With pub/subs you still need to go hunting for a rogue publish.
With my session example, we use the session object to display the user's name in various places. It's easy to use the session object to do this; I can just stick it in the view. With pub/subs, I would have to listen for the publish and then update the view, and I would have to do this in many modules. Turns a 0 line operation into a 5-line one.
> Global objects are evil
Not true at all! A session is a global thing, isn't it? Why wouldn't it belong in the global context? Edicts like "global objects are evil" end up paralyzing your development and you will sometimes have to do even more evil things to get around them.