SlideShare ist ein Scribd-Unternehmen logo
1 von 24
MVVM Design Pattern
How can I implement it on Android
Who I am
david.estivariz@24i.com
destivar
David Estivariz
Android developer
Clean 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 MVVM
MVVM Design Pattern
View ViewModel Model
Data Binding and
Commands
ViewModel updates
the model
Send notifications Send notifications
View ModelPresenter
Presenter updates the
model
User events
Updates Fire events
MVVM Design Pattern
MVVM Design Pattern
Butterknife
Butterknife: before & after
MVVM Design Pattern
MVVM Design Pattern
Dagger
Dagger: before & after
MVVM 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

MVVM with DataBinding on android
MVVM with DataBinding on androidMVVM with DataBinding on android
MVVM with DataBinding on android
 
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveDataAndroid MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID Principles
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Asp.net mvc basic introduction
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introduction
 
Spring jdbc
Spring jdbcSpring jdbc
Spring jdbc
 
Fragment
Fragment Fragment
Fragment
 
Database in Android
Database in AndroidDatabase in Android
Database in Android
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
MVVM
MVVMMVVM
MVVM
 
Sqlite
SqliteSqlite
Sqlite
 
Android Jetpack
Android Jetpack Android Jetpack
Android Jetpack
 
iOS Architectures
iOS ArchitecturesiOS Architectures
iOS Architectures
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Jsf presentation
Jsf presentationJsf presentation
Jsf presentation
 
SQLite database in android
SQLite database in androidSQLite database in android
SQLite database in android
 
MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPF
 

Andere mochten auch

Android - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTaskAndroid - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTask
Hoang Ngo
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
Outware Mobile
 
하이브리드앱
하이브리드앱하이브리드앱
하이브리드앱
knight1128
 

Andere mochten auch (20)

Android Data Binding in action using MVVM pattern - droidconUK
Android Data Binding in action using MVVM pattern - droidconUKAndroid Data Binding in action using MVVM pattern - droidconUK
Android Data Binding in action using MVVM pattern - droidconUK
 
MVVM & Data Binding Library
MVVM & Data Binding Library MVVM & Data Binding Library
MVVM & Data Binding Library
 
Data Binding in Action using MVVM pattern
Data Binding in Action using MVVM patternData Binding in Action using MVVM pattern
Data Binding in Action using MVVM pattern
 
Effective Android UI - English
Effective Android UI - EnglishEffective Android UI - English
Effective Android UI - English
 
Android Data Binding
Android Data BindingAndroid Data Binding
Android Data Binding
 
Memory Leaks in Android Applications
Memory Leaks in Android ApplicationsMemory Leaks in Android Applications
Memory Leaks in Android Applications
 
FFmpeg presentation
FFmpeg presentationFFmpeg presentation
FFmpeg presentation
 
Deep dive into Android Data Binding
Deep dive into Android Data BindingDeep dive into Android Data Binding
Deep dive into Android Data Binding
 
Android data binding
Android data bindingAndroid data binding
Android data binding
 
Android - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTaskAndroid - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTask
 
FFMPEG on android
FFMPEG on androidFFMPEG on android
FFMPEG on android
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
 
Android - Preventing common memory leaks
Android - Preventing common memory leaksAndroid - Preventing common memory leaks
Android - Preventing common memory leaks
 
Android Thread
Android ThreadAndroid Thread
Android Thread
 
하이브리드앱
하이브리드앱하이브리드앱
하이브리드앱
 
Android Databinding Library
Android Databinding LibraryAndroid Databinding Library
Android Databinding Library
 
파크히어 Realm 사용 사례
파크히어 Realm 사용 사례파크히어 Realm 사용 사례
파크히어 Realm 사용 사례
 
Hockey Kit for Android
Hockey Kit for AndroidHockey Kit for Android
Hockey Kit for Android
 
2016 Staccato track3 Android를 더 잘 개발하려면? (MVP, MVVM, Clean Architecture)
2016 Staccato track3 Android를 더 잘 개발하려면? (MVP, MVVM, Clean Architecture)2016 Staccato track3 Android를 더 잘 개발하려면? (MVP, MVVM, Clean Architecture)
2016 Staccato track3 Android를 더 잘 개발하려면? (MVP, MVVM, Clean Architecture)
 
Android Clean Architecture for Dummies
Android Clean Architecture for DummiesAndroid Clean Architecture for Dummies
Android Clean Architecture for Dummies
 

Ähnlich wie Android MVVM

Building an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernateBuilding an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernate
bwullems
 
Presentation Model
Presentation ModelPresentation Model
Presentation Model
Alex Miranda
 
Mvvm pattern
Mvvm patternMvvm pattern
Mvvm pattern
msarangam
 
Socal code camp_usc
Socal code camp_uscSocal code camp_usc
Socal code camp_usc
Nabeel Khan
 

Ähnlich wie Android MVVM (20)

Design patterns in android
Design patterns in androidDesign patterns in android
Design patterns in android
 
Test driving an MVVM App
Test driving an MVVM AppTest driving an MVVM App
Test driving an MVVM App
 
UI Design Patterns
UI Design PatternsUI Design Patterns
UI Design Patterns
 
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
Mvc vs mvp vs mvvm  a guide on architecture presentation patternsMvc vs mvp vs mvvm  a guide on architecture presentation patterns
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
 
WPF with MVVM: From the Trenches
WPF with MVVM: From the TrenchesWPF with MVVM: From the Trenches
WPF with MVVM: From the Trenches
 
Automated Unit Testing in Silverlight for Windows Phone 7
Automated Unit Testing in Silverlight for Windows Phone 7Automated Unit Testing in Silverlight for Windows Phone 7
Automated Unit Testing in Silverlight for Windows Phone 7
 
Modern ASP.NET Webskills
Modern ASP.NET WebskillsModern ASP.NET Webskills
Modern ASP.NET Webskills
 
JavaScript Architectures
JavaScript ArchitecturesJavaScript Architectures
JavaScript Architectures
 
Create first android app with MVVM Architecture
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecture
 
Portable Class Libraries and MVVM
Portable Class Libraries and MVVMPortable Class Libraries and MVVM
Portable Class Libraries and MVVM
 
Building an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernateBuilding an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernate
 
Prism library and MVVM
Prism library and MVVMPrism library and MVVM
Prism library and MVVM
 
Modeling Requirements Narrated2
Modeling Requirements Narrated2Modeling Requirements Narrated2
Modeling Requirements Narrated2
 
Modeling Requirements with SysML
Modeling Requirements with SysML Modeling Requirements with SysML
Modeling Requirements with SysML
 
Javascript from beginning to modern
Javascript from beginning to modernJavascript from beginning to modern
Javascript from beginning to modern
 
Presentation Model
Presentation ModelPresentation Model
Presentation Model
 
Mvvm pattern
Mvvm patternMvvm pattern
Mvvm pattern
 
Socal code camp_usc
Socal code camp_uscSocal code camp_usc
Socal code camp_usc
 
TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0
 
Goals Of Software Design - The main goals
Goals Of Software Design - The main goalsGoals Of Software Design - The main goals
Goals Of Software Design - The main goals
 

Kürzlich hochgeladen

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Kürzlich hochgeladen (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Android MVVM

Hinweis der Redaktion

  1. What is not easy? -> well is not easy to start
  2. Model View Controller The Model View Controller (commonly known as MVC) framework helps you to build applications that are easier to test and maintain. It comprises of three major components, namely: 1 Model -- this is the layer that represents the application's data 2 View -- this represents the presentation or the user interface layer 3 Controller -- this layer typically contains the business logic of your application The primary objective of the MVC design pattern is separation of concerns to facilitate testability. The Model View Controller design pattern enables you to isolate the concerns and makes your application's code easier to test and maintain. In a typical MVC design, the request first arrives at the controller which binds the model with the corresponding view. In the MVC design pattern, the view and the controller makes use of strategy design and the view and the model are synchronized using the observer design. Hence, we may say that MVC is a compound pattern. The controller and the view are loosely coupled and one controller can be used by multiple views. The view subscribes to the changes in the model. Model View Presenter The MVP (Model View Presenter) design pattern also comprises of three components - the model, the view and the presenter. In the MVP design pattern, the Controller (in MVC) is replaced by the Presenter. Unlike the MVC design pattern, the Presenter refers back to the view due to which mocking of the view is easier and unit testing of applications that leverage the MVP design pattern over the MVC design pattern are much easier. In the MVP design pattern, the presenter manipulates the model and also updates the view. There are two variations of this design. These include the following. 1 Passive View -- in this strategy, the view is not aware of the model and the presenter updates the view to reflect the changes in the model. 2 Supervising Controller -- in this strategy, the view interacts with the model directly to bind data to the data controls without the intervention of the presenter. The presenter is responsible for updating the model. It manipulates the view only if needed -- if you need a complex user interface logic to be executed. While both these variants promote testability of the presentation logic, the passive view variant is preferred over the other variant (supervising controller) as far as testability is concerned primarily because you have all the view updated logic inside the presenter. The MVP design pattern is preferred over MVC when your application needs to provide support for multiple user interface technologies. It is also preferred if you have complex user interface with a lot of user interaction. If you would like to have automated unit test on the user interface of your application, the MVP design pattern is well suited and preferred over the traditional MVC design. RESOURCES Model - View - ViewModel (MVVM) The Model - View - ViewModel (MVVM) is a variation of Martin Fowler's Presentation Model design pattern. The MVVM is a refinement of the popular MVC design and the ViewModel in MVVM is used to facilitation Presentation Separation. In the MVVM the logic is stored in the presenter and the view is completely isolated from the model. While the presenter isn't aware of the view, the view is aware of the presenter -- the presenter in MVVM is used to represent an abstract view of the user interface. A passive view implies that the view doesn't have any knowledge of the model. In the MVVM design pattern, the View is active and contains behaviors, events and data binding information. Note that the view in MVVM is not responsible for managing the state information -- the view is rather synchronized with the viewmodel. The viewmodel in MVVM is responsible for presentation separation and exposes methods and commands to manage the state of a view and manipulate the model. How does the view and the viewmodel in MVVM communicate? Well, the view and the viewmodel in MVVM communicates using methods, properties and events. The bi-directional databinding or the two way databinding between the view and the viewmodel ensures that the models and properties in the viewmodel is in sync with the view. The MVVM design pattern is well suited in applications that need support for bi-directional databinding.
  3. I dont have to implement all, if we have tool, libraries, frameworks.. lets use them