Architecture Patterns for Android

            Every operating system and platform has some guidelines for software architecture. These guidelines are general reusable solution that can be used for recurring problems in software development. The architecture patterns separate and define a clear single role for each component in app. A class is not going to be a multi-tasking component. Nowadays, it's very important to define what is the architecture for the application that  we're going to  develop. We need to design for maintainability, scalability, and how testable this application is going to be. Based on maintainability, scalability and testability, we can follow MVC or MVP patterns.

Model-View-Controller (MVC) Pattern

            MVC is most well known in the work development world right now, where basically it's a separation of parts, in other words, the model contains the entities of representation of our objects. The controller, it is basically a formatting for displaying and handling events like the user input, views logic, and the view is how this information is going to be displayed, mainly how the user is going to interact with our applications.
  • Model : The data layer, responsible for managing the business logic and handling network or database API.
  • View : The UI layer — a visualisation of the data from the Model.
  • Controller : The logic layer, gets notified of the user’s behavior and updates the Model as needed.

In MVC both the Controller and the View depend on the Model: the Controller to update the data, the View to get the data. MVC can be of two types :

      1. Passive MVCIn the Passive Model version, the Controller is the only class that manipulates the Model. Based on the user’s actions, the Controller has to modify the Model. After the Model has been updated, the Controller will notify the View that it also needs to update. At that point, the View will request the data from the Model.       
                   
 

      2. Active MVCFor the cases when the Controller is not the only class that modifies the Model, the Model needs a way to notify the View, and other classes, about updates. This is achieved with the help of the Observer pattern. The Model contains a collection of observers that are interested in updates. The View implements the observer interface and registers as an observer to the Model.      
                                                        
 

Model-View-Presenter (MVP) Pattern

            The MVP pattern allows us to separate the presentation layer for the logic, so that everything about how the interface works, is separated for how we represent it on the screen.
  • Model : The data layer. Responsible for handling the business logic and communication with the network and database layers.
  • View : The UI layer. Displays the data and notifies the Presenter about user actions.
  • Presenter : It retrieves the data from the Model, applies the UI logic and manages the state of the View, decides what to display and reacts to user input notifications from the View.                                                                                                                                        

Stay tuned for next article.     

Comments

Popular posts from this blog

Android Process States

Android Overview

Android App Overview