Jonn
Jonn

Reputation: 4661

Why do Presenters attach to View events instead of View calling Presenter Methods in most ASP.NET MVP implementations?

I noticed that in the Webforms MVP implementation and most other examples, the Presenter usually attaches handlers to View events. Why can't the Views just call methods in the presenter directly? Just wondering, since the whole task of attaching a handler to an event, defining EventArgs for special parameters, checking if the event is null on the view side seems a lot more tedious than just calling a method.

Upvotes: 3

Views: 779

Answers (1)

epitka
epitka

Reputation: 17637

Sure they can, and I find that to be the best middle ground. What you are describing is I believe called Observing Presenter style. This allows you to completely decouple View from the Presenter, making the view less susceptible to changes within presenter. But it also introduces complexity in testing, and that is the reason to use MVP to begin with. I would not bother with this style at all. On very large project we use Encapsulated Presenter style, where View has a reference to Presenter, injected via IoC container, and view just calls methods on the Presenter. Easy to understand, easy to debug, easy to test.

Upvotes: 2

Related Questions