Home
+91 99674 50288
info@appmonks.net
×

Importance of MVVM architecture in android


1. In Object-oriented languages like java , c#, c++ had concept of MVC where we can keep model for data, view and controller separate .

Here

• Model is who holds data.

• View who holds visual representation

• Controller who controls both together i.e. who has business logic to bind view and model together.

2. we need an architecture pattern that allows fast reaction to design changes!

The solution we have a tendency to selected within the finish was Model-View-View Model.

The main players in the MVVM pattern are:

• The read — that informs the ViewModel regarding the user’s actions

• The readModel — exposes streams of knowledge relevant to the View

• The DataModel — abstracts the data source. The ViewModel works with the DataModel to get and save the data.

3. At a primary look, MVVM seems very similar to the Model-View-Presenter pattern, because both of them do a great job in abstracting the view’s state and behaviour.

The Presentation Model abstracts a browse freelance from a specific user-interface platform, whereas the MVVM pattern was created to change the event driven programming of user interfaces.


4. If the MVP pattern meant that the Presenter was telling the View directly what to display, in MVVM, ViewModel exposes streams of events to which the Views can bind to.

Like this, the readModel doesn't have to be compelled to hold a relation to the View any longer, like the Presenter is.

This conjointly means all the interfaces that the participant pattern needs, are now dropped.

5. The Views also notify the ViewModel about different actions.

Thus, the MVVM pattern supports two-way knowledge binding between the read and readModel and there's a many-to-one relationship between View and ViewModel.

View encompasses a relation to readModel however readModel has no info concerning the View.The consumer of the info ought to comprehend the producer, however the producer — the ViewModel — doesn’t understand, and doesn’t care, who consumes the info.


 

Is MVVM The Right Solution?

We have been victimization MVVM at the side of RxJava for nearly a year currently.

We have seen that since the read is simply a shopper of the ViewModel, it had been simple to only replace totally different UI components, with borderline, or generally zero changes

in other classes.

We have conjointly learned however necessary separation of considerations is which we should always split the code additional, making little Views and tiny ViewModels that solely have specific responsibilities.

The ViewModels are injected in the Views.

This means that the majority of the days, we have a tendency to simply add the Views within the XML UI, while not doing the other changes.

Therefore, once our UI necessities modification once more, we will simply replace some Views with new ones


Mail
casino