Hi Experts,
I am working on a webform project, where I want to implement MVP Pattern. I have gone through few articles and project based on MVP. It seems fine to me.
At most of the places, If there is any need to display error message, it has been made a method in the view interface. I am giving an example here for clarity.
public interface IAdminSettingsView { string Name { get; set; } string Password { get; set; } string Email { get; set; } void ShowErrorMessage(string errorMessage); }
here is my control implementing IAdminSettingsView
public partial class AdminSettingsEdit : BaseControl, IAdminSettingsView {
private AdminSettingsPresenter _adminSettingsPresenter;
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
_adminSettingsPresenter = new AdminSettingsPresenter(this);
}
protected void BtnSave_Click(object sender, EventArgs e)
{
_adminSettingsPresenter.Save();
}
#region Implementation of IAdminSettingsView
public string Name
{
get { return AdminName.Text; }
set { AdminName.Text = value; }
}
public string Password
{
get { return AdminPassword.Text; }
set { AdminPassword.Text = value; }
}
public string Email
{
get { return AdminEmail.Text; }
set { AdminEmail.Text = value; }
}
public void ShowErrorMessage(string errorMessage)
{
lblErrorMessage.Text = errorMessage;
}
#endregion
}
here is my presenter
public class AdminSettingsPresenter
{
public AdminSettingsPresenter(IAdminSettingsView view)
{
_view = view;
}
private IAdminSettingsView _view;
public void Save()
{
try
{
//Trying Save Data Here
}
catch (Exception exception )
{
_view.ShowErrorMessage("Couldnt Save Data");
}
}
}
My question is, how can I seperate Error Related messages into a different Interface and then make a communication between them. for example if I have an interface
interface IShowErrorMessage { //somemethod here
}
how to use this interface to work with my main IAdminSettingsView interface.
Your help will be appreciated. If there is any better solution to this problem, I would love to hear.
Regards Parminder