Giter Site home page Giter Site logo

android-mvp-pattern's Introduction

##Android MVP Pattern 中文版

This Project offers a simple but clear Android showcase project designed with MVP Pattern (or MVP Framework), which comes to become a more and more important design pattern in Android application project. Besides, MVP used project is easy to changed into MVVM, the future of Android Project.

What is MVP?

Activity and Fragment take most parts of Android Developing jobs.

In traditional Android project, we often write business code and manipulate views directly inside Activity or Fragment. In this case, it is easy to write codes but the Activity or Fragment will become more and more complicated. It takes efforts to read and change. (We usually call this Android standard code style MV Pattern.)

MVP结构

With MVP pattern, the Activity will be just activity, which only does the job of "Find View", "Set Listener" and "React to the LifeCycle". The jobs of UI Logic will be moved to IView, while the jobs of Business Logic will be moved to IPresenter. In this case, the Activity remains very simple and clear, so that it is read-friendly. And since the business logic is written in Presenter, it can be reused in other Activity easily.

By UML, it looks like 简单MVP的UML

Why MVP?

KISS Princeple

"Keep It Stupid Simple". MVP will make the Activity or Fragment much simpler, which means that it is easy to read and change.

Avoid Leak in Background Task

The code of business logic is moved to Presenter. So that all the background tasks (such as HTTP request, File operating) can be written here. We can remove the reference of Activity in Presenter when onDestroy. Since we have separated this tasks from Activity, the Activity will not easily leak when it is onDestroy.

Project Structure

This Project is a sample project used in the following post in my Blog (Android MVP模式 简单易懂的介绍方式). The package structure is as the following table.

Package Description
login Simple MVP usage in Login
loginoptimized Simple MVP usage in Login, avoid Activity leak
outteradapter MVP usage in Adapter
eventbus MVP usage with EventBus
fragments MVP usage in ViewPager

Give MVP a try, tell your friends!

Infomation

android-mvp-pattern's People

Contributors

kaedea avatar

Watchers

James Cloos avatar yue avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.