C# MVP – Should Events Be Handled in the Presenter/Controller?

cmvp

Say I have an MVP app. Should the Presenter handle events raised by the view. For example, please see the code below:

public void TextBox_TypeValidationCompleted(object sender, TypeValidationEventArgs e)
        {
            //do something
        }

and the code below:

public void Button_Click(object sender, EventArgs e)
        {
            //do something
        }

If it should be handled by the presenter, then is it better to:

1) Have an event handler in the view that forwards to a method in the presenter.
2) Handle the event in the presenter directly.

Best Answer

In order to keep your code organized and maintainable, I would say it is better to handle the event in the Presenter. The purpose of the view is to display information to the user. The purpose of the presenter is to execute logic and work as a middle man between data and users.

Related Topic