J'ai besoin de votre aide pour comprendre MVP. J'ai utilisé une interface (IProductEditorView
). Si vous regardez ci-dessous vous pouvez voir la couche de présentation:Question de l'interface du présentateur de modèle?
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;
}
}
}
}
Si vous regardez ci-dessous vous pouvez voir; c'est mélanger ma tête parce que ProductListPresenter(IProductEditorView view)
mais ils veulent me ajouter (this)
. Je ne comprend pas pourquoi "this.mPresenter = new ProductListPresenter(this);
"?
private ProductListPresenter mPresenter;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.mPresenter = new ProductListPresenter(this);
}
devrait probablement supprimer la balise asp.net-mvc. – DSO