SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
MVVM + Data Binding
on Android
Made (with love) by Rodrigo Bresan
What is MVVM?
- Architectural pattern (such as MVC, MVP, VIPER, etc)
- Decouple business logic from user interface
- Model (data) - View (UI) - ViewModel (logic and state)
Data binding
Activities/Fragments/XML
Presentation logic
- State + Behaviour
- Interaction with
Busines/External
Business/Data
Why use it?
- Decouple business logic from user interface
- Abstract Android APIs from business logic
- Better testability
- Follows SOLID principles
Traditional way
- Single activity with many responsibilities:
- Handling state and behaviour of screen (UI widgets);
- Communicating with external world (models);
- Testing becomes harder, due to high being coupled with Android
APIs
Layers
- View
- just UI (components) that displays the data to user
- Model
- Well, data :-)
- ViewModel
- Logic that should be applied on data for being presented
(raw data to friendly)
- Usage of Observable pattern
View
- Working with Android APIs;
- Initializing/Destroying activities;
- Handling toasts, snackbars, dialogs, menus;
- Handling permissions;
View Model
- Handling view states (no connection, empty content, load
content)
- Visibility
- Received extras and arguments
- Input validations
- Fetching data from model
- Uses the application context (since we would use the activity
context only for showing dialogs, starting activities and inflating
layouts)
Model
- Anything that can provides information:
- REST APIs (Retrofit)
- Local storage (Realm, DBFlow, SQLite)
- Shared Preferences
- Firebase
- Sensor Manager
- Geolocation
Testing
- Model and ViewModel can be tested with simple JUnit Tests (mocking
with Mockito), since they don't rely on Android APIs
- View can be tested using Espresso, doing only UI assertions, since all
the logic is being tested on the ViewModel layer
A picture piece of code
is worth a thousand words
https://github.com/bresan/GitHubMVVM

Contenu connexe

Tendances

Introdução a dispositivos móveis.
Introdução a dispositivos móveis.Introdução a dispositivos móveis.
Introdução a dispositivos móveis.
Eduardo Lagares
 

Tendances (20)

Android ppt
 Android ppt Android ppt
Android ppt
 
MVVM in iOS presentation
MVVM in iOS presentationMVVM in iOS presentation
MVVM in iOS presentation
 
Siebel Open UI Presentation
Siebel Open UI PresentationSiebel Open UI Presentation
Siebel Open UI Presentation
 
Hybrid mobile app development
Hybrid mobile app developmentHybrid mobile app development
Hybrid mobile app development
 
Introduction to react native
Introduction to react nativeIntroduction to react native
Introduction to react native
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3
 
Version control system
Version control systemVersion control system
Version control system
 
Introdução a dispositivos móveis.
Introdução a dispositivos móveis.Introdução a dispositivos móveis.
Introdução a dispositivos móveis.
 
Building Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsBuilding Reusable SwiftUI Components
Building Reusable SwiftUI Components
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Reactjs
ReactjsReactjs
Reactjs
 
MVVM & Data Binding Library
MVVM & Data Binding Library MVVM & Data Binding Library
MVVM & Data Binding Library
 
Vue.js
Vue.jsVue.js
Vue.js
 
Conceitos e exemplos em versionamento de código
Conceitos e exemplos em versionamento de códigoConceitos e exemplos em versionamento de código
Conceitos e exemplos em versionamento de código
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Curso de WebServlets (Java EE 7)
Curso de WebServlets (Java EE 7)Curso de WebServlets (Java EE 7)
Curso de WebServlets (Java EE 7)
 
Webdriver io presentation
Webdriver io presentationWebdriver io presentation
Webdriver io presentation
 
Mobile App Testing
Mobile App TestingMobile App Testing
Mobile App Testing
 
iOS architecture patterns
iOS architecture patternsiOS architecture patterns
iOS architecture patterns
 

En vedette

En vedette (19)

Estándar conocer
Estándar conocerEstándar conocer
Estándar conocer
 
ALIANZA INTELIGENTE. APROVECHANDO LA CRISIS
ALIANZA INTELIGENTE. APROVECHANDO LA CRISISALIANZA INTELIGENTE. APROVECHANDO LA CRISIS
ALIANZA INTELIGENTE. APROVECHANDO LA CRISIS
 
THINKING DESIGN
THINKING DESIGNTHINKING DESIGN
THINKING DESIGN
 
Creative critical reflection for a2 advanced portfolio
Creative critical reflection for a2 advanced portfolioCreative critical reflection for a2 advanced portfolio
Creative critical reflection for a2 advanced portfolio
 
Kehadiran ET di dalam Alkitab
Kehadiran ET di dalam AlkitabKehadiran ET di dalam Alkitab
Kehadiran ET di dalam Alkitab
 
Digitalhealtheconomistexcerpt 170228101139
Digitalhealtheconomistexcerpt 170228101139Digitalhealtheconomistexcerpt 170228101139
Digitalhealtheconomistexcerpt 170228101139
 
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
 
Esteroides epidurales
Esteroides epidurales Esteroides epidurales
Esteroides epidurales
 
GESTIÓN CONOCIMIENTO HERRAMIENTAS CAPITAL INTELECTUAAL
GESTIÓN CONOCIMIENTO HERRAMIENTAS CAPITAL INTELECTUAALGESTIÓN CONOCIMIENTO HERRAMIENTAS CAPITAL INTELECTUAAL
GESTIÓN CONOCIMIENTO HERRAMIENTAS CAPITAL INTELECTUAAL
 
Glosarium card teks biografi novita maharani &rilla ajeng.xmm3.vocsten malang
Glosarium card teks biografi novita maharani &rilla ajeng.xmm3.vocsten malangGlosarium card teks biografi novita maharani &rilla ajeng.xmm3.vocsten malang
Glosarium card teks biografi novita maharani &rilla ajeng.xmm3.vocsten malang
 
Our town
Our townOur town
Our town
 
青空文庫テキストフォーマットについて (aozorahack)
青空文庫テキストフォーマットについて (aozorahack)青空文庫テキストフォーマットについて (aozorahack)
青空文庫テキストフォーマットについて (aozorahack)
 
Dominando o Data Binding no Android
Dominando o Data Binding no AndroidDominando o Data Binding no Android
Dominando o Data Binding no Android
 
Testable Android Apps using data binding and MVVM
Testable Android Apps using data binding and MVVMTestable Android Apps using data binding and MVVM
Testable Android Apps using data binding and MVVM
 
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
 
عند بناء محتوى تسويقي... لا تتحدث مع الغرباء!
عند بناء محتوى تسويقي... لا تتحدث مع الغرباء!عند بناء محتوى تسويقي... لا تتحدث مع الغرباء!
عند بناء محتوى تسويقي... لا تتحدث مع الغرباء!
 
Presentación algoritmo
Presentación algoritmoPresentación algoritmo
Presentación algoritmo
 
Video Media
Video MediaVideo Media
Video Media
 
Presentació de la ponència.esc.coop.el puig
Presentació de la ponència.esc.coop.el puigPresentació de la ponència.esc.coop.el puig
Presentació de la ponència.esc.coop.el puig
 

Similaire à MVVM with DataBinding on android

Similaire à MVVM with DataBinding on android (20)

Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
MVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,MobileMVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,Mobile
 
Using mvvm inside mvc in domain driven design
Using mvvm inside mvc in domain driven designUsing mvvm inside mvc in domain driven design
Using mvvm inside mvc in domain driven design
 
IRJET- MVC Framework: A Modern Web Application Development Approach and Working
IRJET- MVC Framework: A Modern Web Application Development Approach and WorkingIRJET- MVC Framework: A Modern Web Application Development Approach and Working
IRJET- MVC Framework: A Modern Web Application Development Approach and Working
 
MVC & backbone.js
MVC & backbone.jsMVC & backbone.js
MVC & backbone.js
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
 
Write cleaner, maintainable, and testable code in Android with MVVM
Write cleaner, maintainable, and testable code in Android with MVVMWrite cleaner, maintainable, and testable code in Android with MVVM
Write cleaner, maintainable, and testable code in Android with MVVM
 
Effort estimation for web applications
Effort estimation for web applicationsEffort estimation for web applications
Effort estimation for web applications
 
J2 ee archi
J2 ee archiJ2 ee archi
J2 ee archi
 
ASP.net MVC Introduction Wikilogia (nov 2014)
ASP.net MVC Introduction Wikilogia (nov 2014)ASP.net MVC Introduction Wikilogia (nov 2014)
ASP.net MVC Introduction Wikilogia (nov 2014)
 
.NET RIA Services Architecture Overview
.NET RIA Services Architecture Overview .NET RIA Services Architecture Overview
.NET RIA Services Architecture Overview
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
 
Introduction To MVVM
Introduction To MVVMIntroduction To MVVM
Introduction To MVVM
 
Android Data Binding Support Library
Android Data Binding Support LibraryAndroid Data Binding Support Library
Android Data Binding Support Library
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!
 
Module2
Module2Module2
Module2
 
Windows phone 8 (mvvm)
Windows phone 8 (mvvm)Windows phone 8 (mvvm)
Windows phone 8 (mvvm)
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 

Dernier

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Dernier (20)

%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
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%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
 
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 🔝✔️✔️
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
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
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

MVVM with DataBinding on android

  • 1.
  • 2. MVVM + Data Binding on Android Made (with love) by Rodrigo Bresan
  • 3. What is MVVM? - Architectural pattern (such as MVC, MVP, VIPER, etc) - Decouple business logic from user interface - Model (data) - View (UI) - ViewModel (logic and state) Data binding Activities/Fragments/XML Presentation logic - State + Behaviour - Interaction with Busines/External Business/Data
  • 4. Why use it? - Decouple business logic from user interface - Abstract Android APIs from business logic - Better testability - Follows SOLID principles
  • 5. Traditional way - Single activity with many responsibilities: - Handling state and behaviour of screen (UI widgets); - Communicating with external world (models); - Testing becomes harder, due to high being coupled with Android APIs
  • 6. Layers - View - just UI (components) that displays the data to user - Model - Well, data :-) - ViewModel - Logic that should be applied on data for being presented (raw data to friendly) - Usage of Observable pattern
  • 7. View - Working with Android APIs; - Initializing/Destroying activities; - Handling toasts, snackbars, dialogs, menus; - Handling permissions;
  • 8. View Model - Handling view states (no connection, empty content, load content) - Visibility - Received extras and arguments - Input validations - Fetching data from model - Uses the application context (since we would use the activity context only for showing dialogs, starting activities and inflating layouts)
  • 9. Model - Anything that can provides information: - REST APIs (Retrofit) - Local storage (Realm, DBFlow, SQLite) - Shared Preferences - Firebase - Sensor Manager - Geolocation
  • 10. Testing - Model and ViewModel can be tested with simple JUnit Tests (mocking with Mockito), since they don't rely on Android APIs - View can be tested using Espresso, doing only UI assertions, since all the logic is being tested on the ViewModel layer
  • 11. A picture piece of code is worth a thousand words https://github.com/bresan/GitHubMVVM