Download - Android MVVM
MVVM Design PatternHow can I implement it on
Android
Who I am
David Estivariz
Android developerClean coding enthusiast
MVVM Design Pattern
What I’m going to talk about?
Clean code and design patterns, why?
Best practices
MVP vs MVVM
Helping Frameworks or libraries
Android MVVM Architecture example
MVVM Design Pattern
MVVM Design pattern
WHY ??
Why I use a design pattern?Easier to read/understand
Easier to scale
Easier to test
Easier to find and resolve bugs
Easier to be applied to any other language (object-oriented)
Reduce technical risk
And a long etc…
MVVM Design Pattern
MVVM Design pattern
How do I start?
Escape from spaghetti code!MVVM Design Pattern
Best Practices Choose your naming well
Use meaningful names …
but don’t state the obvious
Write small methods
Write methods that only do one thing
Encapsulate boolean expressions or overly-complex code
Avoid deep nesting
Replace constructors with builders (see builder pattern)
Use refactoring patterns to fight against legacy
MVVM Design Pattern
MVP vs MVVMMVVM Design Pattern
View ViewModel Model
Data Binding and Commands
ViewModel updates the model
Send notifications Send notifications
View ModelPresenter
Presenter updates the modelUser events
Updates Fire events
MVVM Design Pattern
MVVM Design Pattern
Butterknife
Butterknife: before & afterMVVM Design Pattern
MVVM Design Pattern
Dagger
Dagger: before & afterMVVM Design Pattern
MVVM Design Pattern
Android Binding
MVVM Design Pattern
View - xml layout
MVVM Design Pattern
View - activity
Android Data Binding framework auto generates code
Just get Binding object and set params defined at xml
Then xml will automatically get data from the view model
MVVM Design Pattern
ViewModel
MVVM Design Pattern
Model
Model mustn’t do anything not related with itself
ViewModel will show model changes in the view
Simple and clean
MVVM Design Pattern
Custom Binding Adapters
Using Custom Binding adapters give you more flexibility
A binding adapter can use one or more parameters
Their responsibility is to perform actions in the views depending in parameters from the model
MVVM Design Pattern
Architecture overview
MVVM Design Pattern
Package organisation
MVVM Design Pattern
Any question?
MVVM Design Pattern