Question

MVVM Light and PRISM offer messenger to implement event system.

the approximate interface looks like the following one:

interface Messanger
{
    void Subscribe<TMessageParam>(Action<TMessageParam> action);
    void Unsubscribe<TMessageParam>(Action<TMessageParam> action);
    void Unsubscribe<TMessageParam>(objec actionOwner);
    void Notify<TMessageParam>(TMessageParam param);
}

Now this model seems beneficial comparing to classic .net events. It works well with Dependency Injection. Actions are stored as weak references so memory leaks are avioded and unsubscribe is not a must. The only annoyance is the need to declare new TMessageParam for each specific message. But everything comes at a cost. And what I'm really worried about is that I see no shortcomings of this approach.

Has anoyne the experience of some troubles with this design pattern?

Update
We tried it and the most unpleasant thing with messages is their implicitness from the point of view of interface. Messages contrary to Events are not exposed explicitly in the interface so additional documentation must be provided.
As Laurent said below very loose coupling comes at a cost of vagueness.

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top