Layer supertype for MVP

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 ; }
    }
 
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&lt;IViewType,
IModelType&gt;"/>
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"


转载于:https://www.cnblogs.com/ellipse-gao/archive/2007/10/11/921040.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值