Git Product home page Git Product logo

android-mvp's Introduction

Android MVP

This repository demonstrates the Model View Presenter architecture and was inspired by Antonio Leiva's Android MVP

Videos

Android MVP Playlist - Youtube

Getting Started

  1. Clone the Repo - git clone [email protected]:jpotts18/android-mvp.git
  2. Look at all of the branches - git branch -a
  3. Read about the branches

This repository contains a chain of branches that shows the logical progression of the Android MVP.

  • git checkout 1-login-view - demonstates a simple View which is a LoginActivity
  • git checkout 2-synchronous-login-mvp - demonstrates Login MVP implementation with a synchronous Model (or interactor).
  • git checkout 3-async-login-mvp - demonstrates Login MVP with an asynchronous Model which does not change any code in the LoginActivity
  • git checkout 4-list-activity-view - demonstates a more complex View (RepoListActivity) and an Asynchronous Networked Model which shows a users Github repositories sorted by stars.
  • git checkout 5-list-fragment - substitutes the RepoListActivity for a Fragment without changing any code in the Model.
  • The master branch contains the completed project.

What is MVP?

Model-View-Presenter is a user interface architectural pattern engineered to facilitate automated unit testing and improve the separation of concerns in presentation logic:

  • The Model is an interface defining the data to be displayed or otherwise acted upon in the user interface.
  • The View is a passive interface that displays data (the Model) and routes user commands (events) to the presenter to act upon that data.
  • The Presenter acts upon the model and the view. It retrieves data from repositories (the model), and formats it for display in the view.

Benefits

  • Loose Coupling - The Presenter is an intermediary between the View code and the Model. This allows the View and the Model to evolve independently of each other.
  • Separation of Concerns - Individual sections can be reused, as well as developed and updated independently.
  • More Testable – By isolating each major component (UI, Presenter, and Model) it is easier to write unit tests. This is especially true when using the MVP pattern which only interacts with the view using an interface.
  • Code Reuse – By using a separation of concerns/responsible design approach you will increase code reuse.
  • Flexibility - By isolating most of your code into the Presenter and Model components your code base is more flexible to change in the View.

Key differences between MVC and MVP

MVP Pattern

  • View is more loosely coupled to the model. The presenter is responsible for binding the model to the view.
  • Easier to unit test because interaction with the view is through an interface
  • Usually view to presenter map one to one. Complex views may have multi presenters.

MVC Pattern

  • Controller are based on behaviors and can be shared across views
  • Can be responsible for determining which view to display (Front Controller Pattern)

References

MVC or MVP Pattern – Whats the difference?

Model-View-Presenter - Wikipedia

Separation of Concerns - Wikipedia

android-mvp's People

Contributors

jpotts18 avatar

Watchers

 avatar  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.