Our team of developers took out time to help us better understand app architecture. They also helped us to dissect everything about MVVM.
A lot of developers are familiar with a number of architectures for their applications and one of the most popular is the MVVM architecture which was introduced by Google. MVVM stand for Model – View – View Model. The basic idea of this architecture is to provide data to the view.
During an in-house team session, we happened to have a discussion on architectures used for development, being that our major architecture was the MVVM, we decided to use a sample project to understand why MVVM was the most suitable for our use. Seeing that this issue wasn’t particular to only us, we’ve decided to share our knowledge on the pros and cons of the MVVM to enable developers to decide if it’s suitable for their projects or not.
We will start this article with the Pros and then the Cons and finally discuss how these Cons could be better navigated.
Pros of the MVVM
1. The MVVM as it is called has one very well-known advantage which is that it helps separate the view from the business logic. The Model handles the business logic of the application, the View takes responsibility for displaying the state while the View model is responsible for managing the state of the view and the view model handles and controls everything that happens on the view.
2. Secondly, as developers, we know how important it is to test our applications while in the production phase, the MVVM particularly makes the process seamless as we have our functions outside the view and in the view model. Having the view model enables us to carry tests of functions which is known as the unit test to make sure our codes work as expected
3. Using the MVVM with a state management tool like the provider means we get to save a lot of time rewriting codes for specific functionalities we’ll be needing across various screens. The view model ensures that we only need to call that particular functionality in wherever screen it is needed and this brings that functionality to that screen saving the developer time and energy.
Now we are done discussing the pros of the MVVM architecture, as we might be aware, anything that has an advantage also has a disadvantage. So, we go a step further to discuss the cons.
CONS of the MVVM
On the MVVM, if you’re looking to create a view model for each view, this might look unnecessary as some view models would be too basic for a view thereby making the developer write a lot of boilerplate codes. Following this architecture to the teeth might be a little too much on occasions like this. Having a view model for every view on a small project can be overkill.
Thinking about how to structure your code may be a trivial task, especially when trying to create your models.
Before jumping into code one needs to take time to think about the type of Architecture that would be easy to implement and maintain for a given project.