There has been a lot of talk about Android design templates lately, such as MVP, MVC and MVVM. We strongly advise to use the last one (MVVM Android). Many of mobile apps developers will tell you that ModelView is a very similar solution to the well-known MVC. They kind of have a point and it is partly true. Nonetheless, nuances keep moving forward. So we have to look to the future and pay attention to promising opportunities. What do they have in common and what is the distinction between them? Let us try to reply to the questions together.
 


The Difference between ModelViewViewModel and alternative architecture patterns
 


What’s going to happen if developers announce boycott of architecture design patterns? Most likely, they end it soon. Let’s see how much discomfort that can make. You’ll be forced to write a huge straight line code, make a mess of logic and lose your customer and users.
 


There are more cons than pros. So we have no necessity to discuss the wisdom of using or not using MV*-pattern. In this post we’ll present our own analytical understanding of the differences between the patterns reviewed. This cannot be done unless we consider each case individually. We’d like to start with the oldest but much-needed pattern.

1. The ModelViewController (MVC) architectural solution was determined by Trygve Reenskaug in far 1978/79. It divides a software product into three main logical pillars: Model-View-Editor (renamed Controller).
 


 


The section below shows the comparison of MVC&MVVM standards under Android.


2. The ModelViewPresenter (MVP) showed up later, in 1996. The invention of widgets & visual programming environment have made the redrawing obsolete. This pattern was still in need of view disconnection from logic, but with a high level of abstraction. The quantity of components remained unchanged. But the controller had to be replaced with such presenter. MVP separates UI from its logic. It can therefore be said that MVP is a particular kind of MVC. That means there is not much sense in selecting among them.
 


 


You can find the comparative specifications of Android design patterns below. See MVP vs MVVM.
 

3. The ModelViewViewModel (MVVM) is the youngest member among those under consideration. It was introduced to the world by John Gossman in 2004/05 as an alternative to MVC&MVP approaches. However, it was not entirely new. It belongs to MVC-subset, but has a particular feature, namely Android MVVM data binding. The structure cannot call the view autonomously. View&ViewModel are decoupled here. They could be connected through bindings.
 


 

MVC vs MVVM


The difference between these models is sketched out in the figure below
 


The MVC design pattern was particularly created to decouple the model and the view. For that reason, software developers are able to operate simultaneously with various application components without influencing upon each other.

On other front, such solution has many shortcomings, for example, a confusion in the back-end created by data model controllers. A DataBase (DB) provides individual controller for each mode. Thus, the number of controllers grows when the application scales bigger. In addition, most frameworks generates new abstraction layers, thereby complicating a codebase for navigating.

Let us note that the ViewModel approach is not a controller. It just directly connects the model with view. It operates mainly with application front-end. In this respect, Single-Page-Applications (SPA) operates quite well with Android MVVMs. The principle is very plain and provides the view has direct access to the back-end. Hence, SPAs become fast, fluid and continuous when working with a database. Google docs is the clearest example of that.

MVVM-format, in turn, has its weaknesses too. It demands more memory as compared with its ‘twin’. Large application always face that problem, but not single function/page Web Apps.
 

MVP vs MVVM


Look carefully at the figure below:
 


The major difference among said methods is the way they update the view. ViewModel uses databinding to do that. The presenter applies standards update technique. But is that all they are? Of course, not. Android MVP vs MVVM what are they?
 


Both of them provide good modular structure in comparison with MVC. Simple applications do not require more than MVP, but if you want to build something complex, with the possibility of frequent updating, expanding and scaling, you have to turn your attention to ViewModel. Answer the questions given below and select your own template.


And so on until you get the required answer to your question. But keep in mind that Single-Page(Function)-Application can grow up to be something more. Very often we need MVVMs as an investment in the future of our application. However, note that MVP is recommended, where datacontext binding is impossible. Have you already decided what architecture you want to implement in your Android SW: MVP vs MVVM?
​​​​

The following piece of code illustrates the implementation of ViewModel-pattern:

 

MVVM example
 

Pros for using ViewModel on Android


Let us look at positive factors of using MVVM on Android.
 

  1. The most compelling argument is the popularity of this design pattern both on Android and also iOS operating system. If you are planning to develop some software for multiple platforms, we advise you to apply a similar philosophy to the two frameworks.
     

  2. MVVM separates the view from model through an intermediate ViewModel component. MVC usage may result in undesirable effect, such as the so-called fragile code, and give rise to direct connections between all three levels. This benefits to no one.
     

  3. MVP projects are commonly used to evaluate success in the market because they are cheaper. MVP-application has been piloted in some marketplaces and is expected to be scaled-up following a positive impact evaluation. The second stage will be the finalization of application functions. Scaling and extending will not pose a problem for independent MVVM-pattern. However, if you have forgotten to provide a flexible architecture, you have to do it twice.


Click here to see MVVM architecture Android example.

MVVP-pattern significantly surpasses MVP-solution. It is used in Silverlight, AngularJS, etc. It is very convenient and practical in use. The view properties coincide with View Model/Model, but the View Model by itself isn't connected with the interface. Changes in the ViewModel-status automatically modifies the View and vice versa. To do so, we have to use Data binding techniques. Furthermore, MVVM provides two-way communication.

A system architecture defines the structure, logic layer and interaction between elements and balances the requirements. The correct architecture guarantees a proper distribution of responsibilities, the ease of testing and using low cost and high performance rates. A well chosen design pattern, that is an architectural structure, may indeed become the solution for some often repeated framework. This would allow to separate the graphical interface from business logic layer and the last one from the data. MCCM-representation organizes modules independently from each other. Developers and customers can develop, change or reuse them individually saving significant amounts of time & money.
 

MVVM Android. Followed in Google’s footsteps


Not so long ago, in May 2017, Google made very interesting report on Android architecture components that include MVVM. The company announced the creation of a new library for architecture components consisting of four main blocks:
 


The proposed library will assist in designing dependable, easy-to-test, easy-to-support apps. Library module contains many valuable components, including: the RoomLib to operate with App DataBase, LiveData, Life Cycle Owner(Observer), ViewModel and others.

Google’s MVVM is considered as objects that provide data for UI components. They don’t have any links to the view and are independent from Owner’s Life Cycle. Under this approach we, for one, can modify app configuration without changing the data. The fact that Google has included the MVVM-object to a new library is the evidence that our choice is the right one. Find MVVM architecture example for Android on the Internet if you like.
 

MVVM Android. Our Approach


Even the bad code works, but there is nothing greater in programming than having clean, modular, interdependent software code. WOXAPP uses the same approach as Google. A system architecture determines the composition, logical interaction between elements and balances the requirements. The correct architecture guarantees a proper distribution of responsibilities, the ease of testing and using, low cost and high performance rate. A well chosen design pattern, that is an architectural structure, may indeed become the solution for some oft-repeated framework. That would allow to separate the graphical interface from business logic and the last one from the data. MCCM-representation organizes modules independently from each other. Developers and customers can develop, change or reuse them individually that save significant amounts of time and money.

Our company selected MVVM design pattern because we would like to achieve clean architecture on Android. Presumably, top applications of the near future will be developed on the basis of MVVM-pattern. WOXAPP’s mission is not to simply create a functioning product, but to design the application that will live and be transformed to the market demands.

The mix of Live Data, View Model and Lifecycle Owner, solves the large number of tasks that confronted Android apps (boilerplate code/modularity). The kit of Google libraries includes the main elements required to generate modular, easy-to-test and robust software. You don't necessarily need to use a complete package.

We would like to provide our customers the possibility of cheap and quick changes to their applications, e.g. add new functions or remove something obsolete.

The market changing so fast and the customer needs changing too. We know that latecomers will become redundant. So, we try to keep up to date. And that’s how we do it.




Want an app? Tell us about your business
How to Develop a Shopping App: The Things You Should Know to Promote Your Business to the Top
Internet of Things (IoT): What Can It Do with Your Business and Why Should You Take Benefit of It
Testing of mobile applications and Web projects