所谓MVP(Model-View-Presenter)模式。是将APP的结构分为三层:

view - UI显示层

view 层主要负责:

  1. 提供UI交互
  2. 在presenter的控制下修改UI。
  3. 将业务事件交由presenter处理。
    注意. View层不存储数据,不与Model层交互。

presenter - 逻辑处理层

presenter 层主要负责:

  1. 对UI的各种业务事件进行相应处理。也许是与Model层交互,也许自己进行一些计算,也许控制后台Task,Servic
  2. 对各种订阅事件进行响应,修改UI。
  3. 临时存储页面相关数据。
    注意. Presenter内不出现View引用。

model - 数据层

model层主要负责:

  1. 从网络,数据库,文件,传感器,第三方等数据源读写数据。
  2. 对外部的数据类型进行解析转换为APP内部数据交由上层处理。
  3. 对数据的临时存储,管理,协调上层数据请求。

如图示,里面的activity,presenter,model均为例子:

mvp

将复杂的功能分割为各层内的小问题。各层内功能单一。这样易于功能修改拓展与Debug。
解耦的设计,独立的模块,更有利于分工开发与测试。

简单例子如下

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdAAAAGfCAIAAABgMRTuAAAgAElEQVR4nO3d63MTZ77g8fMHDOfFebFvdrdO1dTULpzaU7WZy+5ZVtiWuXgMZBjfYjxcQryZAiNxiGLAgLEkxwMmQ8wA1hh8wwYseVhb4WIb4japTWV2SPImBWYMTpwLgaFyc6ASW36xVadqX7TUanW3pNbtkS19XZ8XsqxHrXimvtVuief3d7/47/9D9pOf/KSqqspSaAUApGj58uXP/ewXGn9HcAEg7QguAAhiKrjLVhQAAKIhuAAgCMEFAEEILgAIklPBfbujVuO3O36d9VcFALIcDy7NBbB45H5wDWX6lTx3wCdJPvuaVQJWAVgqFl1wm4+f9Bt9uY+fjLs2Wl77uzt6Ir/eOHUmo7/WTW1SEulMbhWApWLRBXdFUdnQ0LCmtv97aGh5YVnctdHOXnt6emLc86M1rn5Jki65ntvePjExISfvR9vbJyYmJiYm+g9ULltRsKlNmpiYaN2+Sv34/7raKd/YdMCnf7D8JbXtXrai4EfLd7dKkvoxy1YUKIeQn1m/CkCOWXTBXbaiYM/BZk1w7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WDv2BeO0Yev+Kf2dI6UlJEYqyXyzBcQhuAi79R5JOVzwYBIBBcABCG4ACAIwQUAQQguAAhCcAFAEIILAIIQXAAQhOBmytsdtRpHbOVZf1UAsojgZoo+uDQXyHMEN1MMg2so6y8VgBgENxav1+s3+hoYGIi7luAC0CC4seyofdkwuC/uiF9JMzFtspU3cZEByBsEN47unh5Nbbu6u80sjBbc//fRr75777l/m93/ePTH3/75v3w++B+fvf8L5aehfWbt7ZKkGu0V2lVWNSFRPRAh678lAGYQ3DjKyis1wd1UXmFmYbTgBm5YZtr/07/N7v/riR/ff+PH/8fx774b/m/KT4P7Z4e309bs0h0xGDHrvxwACSG48Z08dUqpbVvbSZOrogX3pz/76Yr//GO1n/7sp8pPtZNgbJ6JyC+vqzo00obxMMASQ3DjK15bMjw87Pf7h4aGiteWmFyV2iWFcHCjjYEJnQuTXWDJMAzu/wczSnic0Rb86AAAAABJRU5ErkJggg==" alt="" />

UserBean.java

package com.example.mvptest.com.example.bean;

/**
* Created by Administrator on 2016/6/2.
*/
public class UserBean {
private String mobile;
private String userpwd; public UserBean(String mobile, String userpwd) {
this.mobile = mobile;
this.userpwd = userpwd;
} public String getMobile() {
return mobile;
} public String getUserpwd() {
return userpwd;
}
}

Model层

IUserModel.java和UserModel.java

public interface IUserModel {

    void setID(int id);
void setMobile(String mobile);
void setUserPwd(String userpwd);
UserBean load(int id);
}
package com.example.mvptest.com.example.model;

import android.util.SparseArray;

import com.example.mvptest.com.example.bean.UserBean;

/**
* Created by Administrator on 2016/6/2.
*/
public class UserModel implements IUserModel {
private String usermobile;
private String userPwd;
private int mID;
private SparseArray<UserBean> mUserArray = new SparseArray<UserBean>(); @Override
public void setID(int id) {
mID = id;
} @Override
public void setMobile(String mobile) {
usermobile = mobile;
} @Override
public void setUserPwd(String userpwd) {
userPwd = userpwd;
UserBean userBean = new UserBean(usermobile, userpwd);
mUserArray.append(mID, userBean);
} @Override
public UserBean load(int id) {
mID = id;
UserBean userBean = mUserArray.get(mID, new UserBean("no data", "not data"));
return userBean;
}
}

View层

package com.example.mvptest.com.example.view;

/**
* Created by Administrator on 2016/6/2.
*/
public interface IUserView {
int getID();
String getMobile();
String getUserPwd();
void setMobile(String mobile);
void setUserpwd(String userpwd);
}

Presenter层

package com.example.mvptest.com.example.presenter;

import com.example.mvptest.com.example.bean.UserBean;
import com.example.mvptest.com.example.model.IUserModel;
import com.example.mvptest.com.example.model.UserModel;
import com.example.mvptest.com.example.view.IUserView; /**
* Created by Administrator on 2016/6/2.
*/
public class UserPresenter {
private IUserView mUserView;
private IUserModel mUserModel; public UserPresenter(IUserView mUserView) {
this.mUserView = mUserView;
this.mUserModel = new UserModel();
} public void saveUser(int id, String mobile, String userpwd) {
mUserModel.setID(id);
mUserModel.setMobile(mobile);
mUserModel.setUserPwd(userpwd);
} public void loadUser(int id) {
UserBean user = mUserModel.load(id);
mUserView.setMobile("bb"+user.getMobile());
mUserView.setUserpwd(user.getUserpwd());
}
}

Activity层实现IUserView接口

public class MainActivity extends AppCompatActivity implements View.OnClickListener, IUserView{
private EditText mobileEdt, pwdEdt;
UserPresenter presenter; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); findViewById(R.id.save).setOnClickListener(this);
findViewById(R.id.load).setOnClickListener(this); mobileEdt = (EditText) findViewById(R.id.mobile);
pwdEdt = (EditText) findViewById(R.id.passwd); presenter = new UserPresenter(this);
} @Override
public int getID() {
return 3;
} @Override
public String getMobile() {
return mobileEdt.getText().toString();
} @Override
public String getUserPwd() {
return pwdEdt.getText().toString();
} @Override
public void setMobile(String mobile) {
mobileEdt.setText(mobile);
} @Override
public void setUserpwd(String userpwd) {
pwdEdt.setText(userpwd);
} @Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.save:
presenter.saveUser(3, getMobile(), getUserPwd());
break;
case R.id.load:
presenter.loadUser(3);
break;
default:
break;
}
}
}

复杂例子:
https://github.com/wenhuaijun/SearchPictureTool

 

MVP快速开发框架的更多相关文章

  1. XDroidMvp 轻量级的Android MVP快速开发框架

    XDroidMvp是XDroidAndroid快速开发框架的MVP版本,其使用方式类似于XDroid,大部分源码也来自XDroid. XDroidMvp主要会有这些特性: 无需写Contract! 无 ...

  2. Android快速开发框架ZBLibrary源码分享

    坐标标准库ZBLibrary,是一个MVP架构的Android快速开发框架,提供一套开发标准(UI,Data,Listener)以及模板和工具类并规范代码. 封装层级少,简单高效兼容性好.Androi ...

  3. android 快速开发框架

    https://github.com/lipanquan/LPQRapidDevelopmentFramework 依赖LPQLibrary https://github.com/lipanquan/ ...

  4. android悬浮球实现各种功能、快速开发框架、单词、笔记本、应用市场应用等源码

    Android精选源码 悬浮球,实现一键静音,一键锁频,一键截屏等功能 一个Android快速开发框架,MVP架构 Android QQ小红点的实现源码 android一款单词应用完整app源码 an ...

  5. CRL快速开发框架系列教程十三(嵌套查询)

    本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...

  6. CRL快速开发框架系列教程十二(MongoDB支持)

    本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...

  7. CRL快速开发框架系列教程十一(大数据分库分表解决方案)

    本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...

  8. CRL快速开发框架系列教程十(导出对象结构)

    本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...

  9. CRL快速开发框架系列教程九(导入/导出数据)

    本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...

随机推荐

  1. bzoj3875

    悲伤地回忆,当初写了一个作死的算法爆零了为什么不好好写暴力呢……显然设w[i]表示彻底干掉这个怪物的代价注意发现这里的转移具有后效性,但是干掉每个怪物的最优值是一定的我们用spfa来转移,详见那篇sp ...

  2. linux内核驱动中_IO, _IOR, _IOW, _IOWR 宏的用法与解析

    在驱动程序里, ioctl() 函数上传送的变量 cmd 是应用程序用于区别设备驱动程序请求处理内容的值.cmd除了可区别数字外,还包含有助于处理的几种相应信息. cmd的大小为 32位,共分 4 个 ...

  3. ASP.NET MVC 中将FormCollection与实体间转换方法 (转)

    将Action动作中传递的FormCollection转变成对应的实体,可以使用Controller的TryUpdateModel()方法. [HttpPost] public ActionResul ...

  4. DATEDIFF()(转)

    SQL DATEDIFF 函数 Leave a reply SQL DATEDIFF() 函数用来返回2个时间的差.这个函数在SQL Server和MySQL中都有,但语法上有不同. SQL CASE ...

  5. Java学习——数据类型【2】

    1. 对象与类 对象:类的一个实例,有状态和行为. 类:一个模板,描述一类对象的行状态和行为. 2. 类可以包含的变量 类型 局部变量 成员变量 类变量(静态变量) 定义位置 方法.或语句块中 类中, ...

  6. oracle Imp和exp以及导入常见的错误

    一 1) 数据库对象已经存在 一般情况, 导入数据前应该彻底删除目标数据下的表, 序列, 函数/过程,触发器等; 数据库对象已经存在, 按缺省的imp参数, 则会导入失败 如果用了参数ignore=y ...

  7. PHP文件操作常用函数总结

    一 .解析路径: 1 获得文件名: basename(); 给出一个包含有指向一个文件的全路径的字符串,本函数返回基本的文件名.如果文件名是以 suffix 结束的,那这一部分也会被去掉. eg: $ ...

  8. Oracle DB 自动管理共享内存

    • 启用Oracle Enterprise Manager (EM) 内存参数 • 设置自动优化的内存参数 • 使用手动优化的SGA 参数覆盖最小大小 • 使用SGA Advisor 设置SGA_TA ...

  9. JAVA从零单排之前因

    本人,男,21岁,普通院校本科,计算机专业.大学之前对计算机编程没有一点涉及.大学学计算机专业也是个偶然.因为当初高考的成绩不好,结果都是我父亲帮我报的学校和专业. 上了大学之后,大一都是在新奇中度过 ...

  10. 【转】Cannot change version of project facet Dynamic Web Module to 3.1 (Eclipse Maven唯一解决方案)

    If you want to use version 3.1 you need to use the following schema: http://xmlns.jcp.org/xml/ns/jav ...