MVC OR MVVM – Take Your Pick

MVC OR MVVM – Take Your Pick

The architecture of an application is the most important thing when building the application coz the choice you make ensures how flexible is your application and how easy is to build, modify and test it while ensuring that the performance is intact. We being a developer always confused about MVC or MVVM – Take Your pick.

Introduction:-

MVC as we all know stands for Model View Controller is a very popular choice when it comes to the question of designing the architecture of the project. Before we go into the comparison and analyse of the pros and cons of both the architecture.

First let’s understand what are these two terms in layman words:

MVC(Model View Controller): let’s assume an application to be a store. So first of all the view of an application is like the showroom where all the goods are in display, i.e all the interaction with the customer s take apace at the showroom level or the view level. Next, the controller is the salesman who interacts with the customer, heeds the needs and fetches them from their storage or the godown. The model is the godown where employees are working to fetch the required goods, manage it and hand it over to the salesman or the controller so that it can be handed over to the customer or the user.

Here the goods or the commodities are the program data.

The whole idea behind implementing the architectures are to add simplicity and tenacity to the application so that any modification in the application can be facilitated without disrupting the entire program of the application. In practise different types of MVC are used but we are not going into that. The above explanation may be over simplification of a huge topic such as MVC but the above description may be enough to get an idea as to what it is.

MVVM (Model View View Model) :

is an architectural pattern used in software engineering that originated from Microsoft. It is a derivative of the traditional MVC with the difference that the Controller layer is replaced with a layer which is a combination of both Model and View. This type of architecture is super popular and perhaps tailor made when it comes to mobile application building. The main idea behind this is to separate business logic from its view (user interface). This enables designers and programming to work on a solution without conflict. Information is bound to views but no calculations or logic is found in the views. Making it cleaner and much easier to maintain. Here the model is dragged down to represent only the presentation level data that can be displayed. This is very helpful with the interactivity and the features of the application increasing each day dynamically. Some of the framework that support MVVM are : Angular JS , Rails for Ruby,Xamarin, Silverlight,etc

Advantages of MVC :

The MVC pattern is simple and makes it easier to test applications and manage their complexity by dividing the applications into the model, the view and the controller.

The MVC framework is ideal for developers who want full control over the behaviour of an application, as it does not use view state or server-based forms.

Due to the fact that it does not have support for view state, there will not be any automatic state management, reducing the page size, which allows for better performance.

Advantages of MVVM :

Here the model does not know anything about the view or any other parts of the program as its interaction is limited to view model layer. The view is dumbed down and has no role except to present data and its interaction is limited to the view model layer.

1.This pattern is pretty good because you can test your view models.

Developers can create unit tests for the view model and the model without using the view and the unit tests can exercise exactly the same functionality as used by the view.

The MVVM pattern provides two-way communication between the pattern parts, whereas MVC is able only to provide one-way communication.

4.That testability from MVC would have 30%, with MVVM you could get to 70% and you could have UI tests for the rest.

Some other Names:

Viper: This architecture are basically targeted towards the mobile platform. The word VIPER is a backronym for View, Interactor, Presenter, Entity, and Routing. Clean Architecture divides an app’s logical structure into distinct layers of responsibility. This makes it easier to isolate dependencies (e.g. your database) and to test the interactions at the boundaries between layers:. It helps to target the problem of Massive View Controller problem in the iOS application where the view controller ends up doing a lot of stuffs. ensuring the VIPER architecture the developers can slimmer the chances of massive view controllers.

Main Parts of VIPER

View: displays what it is told to by the Presenter and relays user input back to the Presenter.

Interactor: contains the business logic as specified by a use case.

Presenter: contains view logic for preparing content for display (as received from the Interactor) and for reacting to user inputs (by requesting new data from the Interactor).

Entity:- It contains basic model objects used by the Interactor.

Routing: contains navigation logic for describing which screens are shown in which order.

Conclusion:

The choice of the architecture is totally dependent on the developer but a good analysis of the project especially its requirements is essential. We will cover more topics related to the project architecture and performance enrichments of applications. Till then keep following our blog at Frugalis Minds