MVP Pattern on Android
taken from https://valokafor.com/

MVP Pattern on Android

In this article I will explain how to create a basic application with WVP pattern, all the code is available here: Gitlab repository.

For this tutorial I asume that you are already familiar with Android development and the java programming lenguaje, so I won't explain the most basic things about creation an Android application or basics in java programming. For basic information there are many good sources of information in internet like Udacity.

What is MVP?

MVP stands for Model View Controller, this pattern helps to separate all the related functionality from how it is represented on the screen. That means that it would be possible to replace the design with cero extra work, since all the logic is in a different layer.

MVP project example

This project contains a small example on how create an Android application using the MVP pattern, for this I use one of the most common functionalities in an application, the login process.

How the example application was created?

First create a project in AndroidStudio with the following packages

Inside the control package create the following classes

ControlActivity is the start point of the application and it basically send the user to the login screen. It will implements the ControlView interface and will create the ControlPresenterImpl instance.

The ControlPresenterImpl will hace a reference to the activity and will have the logic related to the screen, is this case there is no screen, so it will only contains the intent to the login

Now the login process, this will show how is the interaction between the layers. In the login package create the following classes and interfaces.

The LoginActivity will implement the LoginView interface which provides all methods that will be used for communication between the view and the presenter, like show the login errors for example.

The LoginPresenterImpl will implement the LoginPresenter interface, which will handle the events from the view and will call the methods that actually have some functionality in the interactors.

Complete code can be found https://github.com/LycanDev/MVP_pattern

Anderson M. Monta?ez

Principal Software Engineer @ R2

7 年

Great hands-on start point for android MVP pattern Alexander Cabezas Medina, I think that this code could be the foundation to teach something more advanced, like DI using dagger. Anyways, I'm just giving you some ideas since I can see that you're having fun while writing android tutorials :D, regards !

回复

要查看或添加评论,请登录

Alexander Cabezas Medina的更多文章

  • How to recruit a software developer?

    How to recruit a software developer?

    The demand for software developers is increasing rapidly, especially for those with years of experience and knowledge…

  • The HDD (Hype Driven Development) what is it?

    The HDD (Hype Driven Development) what is it?

    I call HDD (Hype Driven Development) the development process in which Libraries, programming languages, frameworks or…

    2 条评论
  • Repository pattern on Android

    Repository pattern on Android

    This article is on how implement the repository pattern with multiple data sources on Android. Before starting I assume…

  • Viper Architecture on Android

    Viper Architecture on Android

    In this article I will explain how to create a basic application with VIPER architecture, all the code is available…

    2 条评论

社区洞察

其他会员也浏览了