zoukankan      html  css  js  c++  java
  • mvp解读


    mvp存在的问题
          1.业务复杂时,可能使得Activity变成更加复杂,比如要实现N个IView,然后写更多个模版方法。
    2.业务复杂时,各个角色之间通信会变得很冗长和复杂,回调链过长。
    3.Presenter处理业务,让业务变得很分散,不能全局掌握业务,很难去回答某个业务究竟是在哪里处理的。
    4.用Presenter替代Controller是一个危险的做法,可能出现内存泄漏,生命周期不同步,上下文丢失等问题。
    mvc存在的问题
         (1)完全理解MVC并不是很容易。使用MVC需要精心的计划,由于它的内部原理比较复杂,所以需要花费一些时间去思考。同时由于模型和视图要严格的分离,这样也给调试应用程序带来了一定的困难。每个构件在使用之前都需要经过彻底的测试。
    (2)对于小项目,MVC反而会带来更大的工作量以及复杂性。
    mpv框架
    view层写法
    public abstract class MVPBaseActivity<V, T extends BasePresenter<V>> extends Activity {
    protected T mPresenter; //Presenter对象

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPresenter = createPresenter();
    mPresenter.attachView((V)this);
    }

    @Override
    protected void onDestroy() {
    super.onDestroy();
    mPresenter.detachView();
    }

    protected abstract T createPresenter();
    }
    presenter层写法
    public abstract class BasePresenter<T> {
    protected Reference<T> mViewRef; //View接口类型的弱引用

    public void attachView(T view){
    mViewRef = new WeakReference<T>(view); //建立关联
    }

    protected T getView(){
    return mViewRef.get(); //获取View
    }

    public boolean isViewAttached(){
    return mViewRef != null && mViewRef.get() != null; //判断是否与View建立关联
    }

    public void detachView(){
    if(mViewRef != null){
    mViewRef.clear(); //解除关联
    mViewRef = null;
    }
    }
    }

    model层写法
  • 相关阅读:
    mysql----show slave status G 说明
    mysqldump 的方式来搭建master-->slave 的复制架构
    C++----练习--string 从文件中一个一个单词的读直到文件尾
    python 全排列combinations和permutations函数
    什么是restful api
    git知识点
    Hash算法解决冲突的方法
    python之单例设计模式
    Linux常用命令大全
    SQLAlchemy中时间格式化及将时间戳转成对应时间的方法-mysql
  • 原文地址:https://www.cnblogs.com/mamamia/p/8444687.html
Copyright © 2011-2022 走看看