SlideShare a Scribd company logo
Activities and Fragments are
not MVxViews
Vasiliy Zukanov
Consultant, developer, blogger
MVx:
@VasiliyZukanov 2
Family of architectural patterns featuring concerns
separation for GUI applications
Model : application state + business logic (optional)
View : application user interface
x : application logic + business logic (optional)
How I became an Android developer:
@VasiliyZukanov 3
Official documentation Blogs
After a short while:
@VasiliyZukanov 4
Fragments of 500+ lines of code are the norm!?
Google for “android application architecture”:
@VasiliyZukanov 5
Exactly what I looked for… said no one ever.
The best place to hide a dead body is page 2 of
Google search results
I saw pages 2, 3, 4…
Android Architecture: Message-based MVC[1]
@VasiliyZukanov 7
View Controller Model
Activity
Tremendous improvement…
… but still didn’t feel quite right.
Android Architecture [in 10 parts][2]
@VasiliyZukanov 9
Joshua Musselwhite’s Breakthrough:
@VasiliyZukanov 10
View Controller Model
Activity
What’s the main advantage of any MVx
architecture?
Decoupled UI logic!
UI logic characteristics:
Much higher rate of change in most cases
Not directly related to core functionality in most cases
Unreadable - verbose, messy, hacky, etc.
Easiest to test manually
Hardest to test automatically
@VasiliyZukanov 12
development and maintenance
testing
Why not decouple UI logic by encapsulation
inside Activity?
Project advantage!
Outsourcing:
@VasiliyZukanov 14
UI isn’t directly related to
core functionality
Detailed UI specification
MyActivity
<<interface>>
MyViewMvc
The whole picture:
@VasiliyZukanov 15
MyActivity
<<interface>>
MyViewMvc
Lifecycle
Screens navigation
Runtime permissions
Loaders
Dependency injection
Fragments
Dialogs
More…
* this coupling exists even when developing in-house
UI logic
Outsourcing UI development is hard when UI
logic resides in Activities.
A/B testing:
@VasiliyZukanov 17
BUY
A/B testing – approach 1:
@VasiliyZukanov 18
MyActivity.java
Different XML layout
Different product data
Read code… Add test code… Remove test code… Bugs…
MyActivity2.java
A/B testing – approach 2:
@VasiliyZukanov 19
MyActivity.java
Duplication hell…
MyActivity3.java
Bug fix 1 Bug fix 1 Bug fix 1
Bug fix 2 Bug fix 2
Can we do better than this?
Yes!
Extract UI logic into standalone classes:
@VasiliyZukanov 21
MyViewMvcImplMyActivity
<<interface>>
MyViewMvc
Composition instead of inheritance
Controller
UI logic
Activity only aware of simple interfaces:
@VasiliyZukanov 22
public interface ViewMvc {
View getRootView();
}
public interface MyViewMvc extends ViewMvc {
interface Listener {
void onBuyClicked();
}
void bindProduct(Product product);
void registerListener(Listener listener);
void unregisterListener(Listener listener);
}
setContentView(mViewMvc.getRootView())
Project advantages:
Outsource development of implementations of MVC views
Inject alternative implementations during A/B testing
More…
@VasiliyZukanov 23
Disadvantages:
Different mental model
Initial ramp-up
More code
Requires discipline
@VasiliyZukanov 24
Summary:
Extracting UI logic from Activities allows for easier
development and maintenance
Advantages up to project and business level
Activity can take on its natural role – controller
Mature and documented[3]
@VasiliyZukanov 25
But what about Fragments?
Replace “activity” with “fragment” and re-read the
presentation.
Questions
@VasiliyZukanov 27
Thank you!
@VasiliyZukanov 28
www.TechYourChance.com
References
1. Android Architecture: Message-based MVC - http://mindtherobot.com/blog/675/android-
architecture-message-based-mvc/
2. Android Architecture [in 10 parts] - http://www.therealjoshua.com/2011/11/android-
architecture-part-1-intro/
3. Activities in Android are not UI Elements - https://www.techyourchance.com/activities-
android/
@VasiliyZukanov 29

More Related Content

What's hot

Design Nelle Applicazioni Ria
Design Nelle Applicazioni RiaDesign Nelle Applicazioni Ria
Design Nelle Applicazioni Ria
roberto.design
 
Animation And Testing In AngularJS
Animation And Testing In AngularJSAnimation And Testing In AngularJS
Animation And Testing In AngularJS
Edureka!
 

What's hot (7)

Infographic useful frameworks
Infographic useful frameworksInfographic useful frameworks
Infographic useful frameworks
 
Angular.js interview questions
Angular.js interview questionsAngular.js interview questions
Angular.js interview questions
 
Webinar on Angular JS titled 'Develop Responsive Single Page Application'
Webinar on Angular JS titled 'Develop Responsive Single Page Application'Webinar on Angular JS titled 'Develop Responsive Single Page Application'
Webinar on Angular JS titled 'Develop Responsive Single Page Application'
 
Building UWP apps with React-Native
Building UWP apps with React-NativeBuilding UWP apps with React-Native
Building UWP apps with React-Native
 
Design Nelle Applicazioni Ria
Design Nelle Applicazioni RiaDesign Nelle Applicazioni Ria
Design Nelle Applicazioni Ria
 
Sony lazuardi native mobile app with javascript
Sony lazuardi   native mobile app with javascriptSony lazuardi   native mobile app with javascript
Sony lazuardi native mobile app with javascript
 
Animation And Testing In AngularJS
Animation And Testing In AngularJSAnimation And Testing In AngularJS
Animation And Testing In AngularJS
 

Similar to Activities and Fragments are not MVx views - Vasiliy Zukanov

Universal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Universal programming recipes​ - Ekaterina Trofimenko - Women In TechnologyUniversal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Universal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Badoo
 

Similar to Activities and Fragments are not MVx views - Vasiliy Zukanov (20)

New Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy ZukanovNew Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy Zukanov
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderDesign Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-Binder
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
 
#7 - Client-side web apps, MVC and jQuery
#7 - Client-side web apps, MVC and jQuery#7 - Client-side web apps, MVC and jQuery
#7 - Client-side web apps, MVC and jQuery
 
"Universal programming recipes", Kateryna Trofimenko
"Universal programming recipes", Kateryna Trofimenko"Universal programming recipes", Kateryna Trofimenko
"Universal programming recipes", Kateryna Trofimenko
 
Universal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Universal programming recipes​ - Ekaterina Trofimenko - Women In TechnologyUniversal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Universal programming recipes​ - Ekaterina Trofimenko - Women In Technology
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009
 
OpenDolphin with GroovyFX Workshop at GreachConf, Madrid
OpenDolphin with GroovyFX Workshop at GreachConf, MadridOpenDolphin with GroovyFX Workshop at GreachConf, Madrid
OpenDolphin with GroovyFX Workshop at GreachConf, Madrid
 
MoSKito at Silpion Solutionscamp 2014
MoSKito at Silpion Solutionscamp 2014MoSKito at Silpion Solutionscamp 2014
MoSKito at Silpion Solutionscamp 2014
 
Introduction to Configurator 2.0 architecture design
Introduction to Configurator 2.0 architecture designIntroduction to Configurator 2.0 architecture design
Introduction to Configurator 2.0 architecture design
 
JavaScript for ASP.NET programmers (webcast) upload
JavaScript for ASP.NET programmers (webcast) uploadJavaScript for ASP.NET programmers (webcast) upload
JavaScript for ASP.NET programmers (webcast) upload
 
MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )
 
Anshulika Verma_p.pptx
Anshulika Verma_p.pptxAnshulika Verma_p.pptx
Anshulika Verma_p.pptx
 
Micro-Frontends JSVidCon
Micro-Frontends JSVidConMicro-Frontends JSVidCon
Micro-Frontends JSVidCon
 
New Android Project - The Most Important Decisions (Droidcon TLV 2019)
New Android Project - The Most Important Decisions (Droidcon TLV 2019)New Android Project - The Most Important Decisions (Droidcon TLV 2019)
New Android Project - The Most Important Decisions (Droidcon TLV 2019)
 
Large-Scale Web Development with JavaScript
Large-Scale Web Development with JavaScriptLarge-Scale Web Development with JavaScript
Large-Scale Web Development with JavaScript
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applications
 
Models used in iOS programming, with a focus on MVVM
Models used in iOS programming, with a focus on MVVMModels used in iOS programming, with a focus on MVVM
Models used in iOS programming, with a focus on MVVM
 
Continuous workflow for a large react native app - mobile at wix
Continuous workflow for a large react native app - mobile at wixContinuous workflow for a large react native app - mobile at wix
Continuous workflow for a large react native app - mobile at wix
 
FRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JSFRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JS
 

More from DroidConTLV

More from DroidConTLV (20)

Mobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, NikeMobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, Nike
 
Doing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra TechnologiesDoing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra Technologies
 
No more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola SolutionsNo more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola Solutions
 
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.comMobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
 
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, ClimacellLiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
 
MVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, LightricksMVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, Lightricks
 
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
 
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice NinjaBuilding Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice Ninja
 
Designing a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, GettDesigning a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, Gett
 
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperThe Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
 
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDevKotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
 
Flutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, TikalFlutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, Tikal
 
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisReactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
 
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevelFun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
 
DroidconTLV 2019
DroidconTLV 2019DroidconTLV 2019
DroidconTLV 2019
 
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, MondayOk google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
 
Introduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, WixIntroduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, Wix
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
 
Educating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz TamirEducating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz Tamir
 
Constraint-ly motion - making your app dance - John Hoford, Google
Constraint-ly motion - making your app dance - John Hoford, GoogleConstraint-ly motion - making your app dance - John Hoford, Google
Constraint-ly motion - making your app dance - John Hoford, Google
 

Recently uploaded

Recently uploaded (20)

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 

Activities and Fragments are not MVx views - Vasiliy Zukanov