Android MVVM
Click here to load reader
-
Upload
vinicius-t-sossella -
Category
Mobile
-
view
107 -
download
0
Transcript of Android MVVM
Android MVVM
Vinícius T. Sossella
MVVM
Model-View-View Model (MVVM) is a design pattern for building user interfaces
Was created in 2005 by John Gossman, the Microsoft WPF and Silverlight architect
Similar to MVC and MVP, we can say that MVVM is an MVP specialization.
https://blogs.msdn.microsoft.com/johngossman/2005/10/08/introduction-to-modelviewviewmodel-pattern-for-building-wpf-apps/
MVVM
View - The view is responsible for defining the structure, layout, and appearance of what the user sees on the screen.
Model - Encapsulates the application's business logic and data.
View Model - The view model acts as an intermediary between the view and the model, and is responsible for handling the view logic. Typically, the view model interacts with the model by invoking methods in the model classes. The view model retrieves data from the model and then makes the data available to the view, and may reformat the data in some way that makes it simpler for the view to handle.
Advantages
- Helps you to cleanly separate the business and presentation logic of your application from its user interface (UI)- Unlike the Presenter in MVP, a ViewModel does not need a reference to a view. The view binds to properties on a ViewModel, which,
in turn, exposes data contained in model objects and other state specific to the view. - Easier to test- Improve code re-use opportunities
'you can test it without awkward UI automation and interaction. If you’ve ever tried to unit test UI code, you know how hard that can be.' JohnGossmanMarch 4, 2006
Disadvantages
- Bindings (but wait android did it well)- In bigger cases, it can be hard to design the ViewModel
MVVM
Do we need all this stupid code every time?
Did I study for this??!!
Android Data Binding
https://developer.android.com/topic/libraries/data-binding/index.html
Android Data Binding
- Announced at Google I/O 2015
- Allows you to write declarative layouts and minimize the glue code necessary to bind your data and layouts
- Allows you to bind values of an object directly to views in your layout, and if the object changes, the view is updated automatically
- By binding properties of a view to a ViewModel, you get loose coupling between the two and entirely remove the need for writing code in a ViewModel that directly updates a view.
Disavantages
- Bindings (but wait android did it well)
The binding objects are created at compile time. All other databinding needed refletion, but not the new one (Android Data Binding)
MVVM
Android Data Binding
- How to use?
Add to Gradle file
Android Data Binding
Android Data Binding
Android Data Binding
ENDVinicius Tonial Sossella