Mvp模式学习中...
来源:互联网 发布:中行网银安全控件mac 编辑:程序博客网 时间:2024/06/08 07:08
这是百度上的区别写的非常明白!
我学了几天的mvp了在新项目的构建上也尝试使用了mvp但是有点走火入魔的感觉,总是把mvp模式写着写着写成了mvc模式,mvp模式和mvc模式的
最大的区别在于view层不直接访问model层这提供了很好的测试性,并且为了降低耦合度需要写大量的接口。
关于data层官方写了这样一个接口:
使用constract类来包含presenter 和 view
/*
* Copyright 2016, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.architecture.blueprints.todoapp.addedittask;
import com.example.android.architecture.blueprints.todoapp.BasePresenter;
import com.example.android.architecture.blueprints.todoapp.BaseView;
/**
* This specifies the contract between the view and the presenter.
*/
public interface AddEditTaskContract {
interface View extends BaseView<Presenter> {
void showEmptyTaskError();
void showTasksList();
void setTitle(String title);
void setDescription(String description);
boolean isActive();
}
interface Presenter extends BasePresenter {
void saveTask(String title, String description);
void populateTask();
boolean isDataMissing();
}
}
fragment和presenter中分别实现了这几个接口。
然后在presenter中操作fragment的显示。
我认为mvp模式的主体思想就是写一些接口来降低耦合,
然后将逻辑代码写在presenter然后data存在model中然后所有的行为都在presenter中操作。
为了提高代码的复用专注于操作presenter。都会封装一个baseview,basepresenter,baseavtivity<T extends basepresenter>
将presenter的set写在baseactivity并且实例化泛型,那是前辈的一个实例化泛型的代码,非常神奇,继承baseactivty后可以直接拿到presenter直接使用,可是这段代码现在我拿不到。
- Mvp模式学习中...
- MVP模式学习
- MVP模式学习
- android:MVP模式学习
- Retrofit+MVP模式学习
- 初次学习MVP模式
- MVP模式学习笔记
- MVP模式的学习
- 学习一下MVP模式
- Android MVP模式学习
- android中MVP模式
- android中MVP模式
- android中MVP模式
- android中MVP模式
- android中MVP模式
- [Android学习]Android中MVP模式初探1
- SimpleNews- Android MVP模式学习
- 学习和认识mvp模式
- Intellij IDEA修改代码补全快捷键
- 使用Solr索引MySQL数据
- 一个简单的Linux Shell
- 【编程素质】算法-二分搜索
- 架构学习-----架构概览(一)
- Mvp模式学习中...
- 多线程排序程序
- liunx初级学习之使用逻辑卷管理器灵活管理2-5
- 字节序和lsof
- jquery:获取checked复选框的问题
- 循环队列的简单实现
- NYOJ-ACM-数数小木块
- 编写Linux内核程序查看优先级对程序运行的影响
- 计算机基础小题目