Presenter:
public interface IPresenter
{
/// <summary>
/// Binds the view.
/// </summary>
/// <param name="view"> The view. </param>
void BindView( object view);
/// <summary>
/// Binds the model.
/// </summary>
/// <param name="model"> The model. </param>
void BindModel( object model);
/// <summary>
/// Gets the type of view.
/// </summary>
/// <value> The type of view. </value>
Type TypeOfView { get ; }
/// <summary>
/// Gets the type of model.
/// </summary>
/// <value> The type of model. </value>
Type TypeOfModel { get ; }
}
public interface IPresenter
{
/// <summary>
/// Binds the view.
/// </summary>
/// <param name="view"> The view. </param>
void BindView( object view);
/// <summary>
/// Binds the model.
/// </summary>
/// <param name="model"> The model. </param>
void BindModel( object model);
/// <summary>
/// Gets the type of view.
/// </summary>
/// <value> The type of view. </value>
Type TypeOfView { get ; }
/// <summary>
/// Gets the type of model.
/// </summary>
/// <value> The type of model. </value>
Type TypeOfModel { get ; }
}
the common actions for presenter is that: know the IModel and IView
public
abstract
class
Presenter
<
ViewType, IModelType
>
: IPresenter
// where IModelType : IServiceInterface
{
/// <summary>
/// The view
/// </summary>
protected ViewType view;
/// <summary>
/// The model
/// </summary>
protected IModelType model;
/// <summary>
/// Gets a value indicating whether this <see cref="Presenter<IViewType,
IModelType>"/> is initialized.
/// Only when both view and model are binded, a presenter is initialized.
/// </summary>
/// <value><c> true </c> if initialized; otherwise, <c> false </c> . </value>
public bool Initialized
{
get
{
return view != null && model != null ;
}
}
#region IPresenter Members
/// <summary>
/// Binds the view.
/// </summary>
/// <param name="view"> The view. </param>
public void BindView( object view)
{
Check.Require(view != null , " view could not be null. " );
Check.Require( typeof (ViewType).IsAssignableFrom(view.GetType()),
" view's type does not match Presenter's view type. " );
this .view = (ViewType)view;
}
/// <summary>
/// Binds the model.
/// </summary>
/// <param name="model"> The model. </param>
public void BindModel( object model)
{
Check.Require(model != null , " model could not be null. " );
Check.Require( typeof (IModelType).IsAssignableFrom(model.GetType()),
" model's type does not match Presenter's model type. " );
this .model = (IModelType)model;
}
/// <summary>
/// Gets the type of the view.
/// </summary>
/// <value> The type of the view. </value>
public Type TypeOfView
{
get
{
return typeof (ViewType);
}
}
/// <summary>
/// Gets the type of the model.
/// </summary>
/// <value> The type of the model. </value>
public Type TypeOfModel
{
get
{
return typeof (IModelType);
}
}
#endregion
}
// where IModelType : IServiceInterface
{
/// <summary>
/// The view
/// </summary>
protected ViewType view;
/// <summary>
/// The model
/// </summary>
protected IModelType model;
/// <summary>
/// Gets a value indicating whether this <see cref="Presenter<IViewType,
IModelType>"/> is initialized.
/// Only when both view and model are binded, a presenter is initialized.
/// </summary>
/// <value><c> true </c> if initialized; otherwise, <c> false </c> . </value>
public bool Initialized
{
get
{
return view != null && model != null ;
}
}
#region IPresenter Members
/// <summary>
/// Binds the view.
/// </summary>
/// <param name="view"> The view. </param>
public void BindView( object view)
{
Check.Require(view != null , " view could not be null. " );
Check.Require( typeof (ViewType).IsAssignableFrom(view.GetType()),
" view's type does not match Presenter's view type. " );
this .view = (ViewType)view;
}
/// <summary>
/// Binds the model.
/// </summary>
/// <param name="model"> The model. </param>
public void BindModel( object model)
{
Check.Require(model != null , " model could not be null. " );
Check.Require( typeof (IModelType).IsAssignableFrom(model.GetType()),
" model's type does not match Presenter's model type. " );
this .model = (IModelType)model;
}
/// <summary>
/// Gets the type of the view.
/// </summary>
/// <value> The type of the view. </value>
public Type TypeOfView
{
get
{
return typeof (ViewType);
}
}
/// <summary>
/// Gets the type of the model.
/// </summary>
/// <value> The type of the model. </value>
public Type TypeOfModel
{
get
{
return typeof (IModelType);
}
}
#endregion
}
likewise, you can have several IModel for a presenter as well.
then we can have a PresenterFactory responsible for the action "BindModel" and "BindView"