I need your help to understand MVP. I used a interface (IProductEditorView
). If you look below you can see presentation layer:
using System;
using System.Collections.Generic;
using System.Text;
using MVPProject.BusinessLayer;
namespace MVPProject.PresentationLayer
{
public interface IProductEditorView
{
int ProductID { get;}
string ProductDescription { get; }
event EventHandler<EventArgs> Save;
}
public class ProductEditorPresenter
{
private IProductEditorView mView;
public ProductEditorPresenter(IProductEditorView view)
{
this.mView = view;
this.Initialize();
}
private void Initialize()
{
this.mView.Save += new EventHandler<EventArgs>(mView_Save);
}
private void mView_Save(object sender, EventArgs e)
{
Product product;
try
{
product = new Product();
product.Description = mView.ProductDescription;
product.ID = mView.ProductID;
product.Save();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
throw;
}
}
}
}
If you look below you can see; this is mixing my head because ProductListPresenter(IProductEditorView view)
but they want me add (this)
. I don't understand why "this.mPresenter = new ProductListPresenter(this);
" ?
private ProductListPresenter mPresenter;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.mPresenter = new ProductListPresenter(this);
}