SlideShare a Scribd company logo
Architectural Design
Pattern
MVC, MVP & MVVM
What & Why
Design Pattern
What is Design Pattern
In software engineering, a design pattern is a general repeatable solution to a commonly
occurring problem in software design. A design pattern isn't a finished design that can be
transformed directly into code. It is a description or template for how to solve a problem that can
be used in many different situations.
Need of Design Pattern?
1. To solve a recurring problem in software development
1. To represent a relationships between classes and objects with defined
responsibilities to carry out the solution in a concrete way
1. To develop highly cohesive modules with minimal coupling
Requirement &
Implementation
Design Pattern
Problem Statement
Consider the following story -
Story: As a user, i must be able to get a successful status so that i can find out
whether user id and password given by me is correct or not.
Model: UserInfo(userId, password)
View: InputBox(userId), InputBox(password), actionButton
Note: For the story above, Model and View will remain same and we will see how to implement them in MVC, MVP and
MVVM.
Solution
Design Pattern: MVC
M V & Controller
Consider designing a Login Controller with a method onLogin which will execute when login button gets clicked
in View defined in problem statement
LoginController{
doLogin(String userId, String password){
//PERFORM OPERATION FOR PROCESSING THE LOGIN DETAIL
//ACT ON OR DELEGATE RESULT TO VIEW
}
M V & Controller
Now, during the integration of LoginController with View, there is no mandatory rule to delegate result to View
by using Java Interface and there may be chance that the result gets processed inline in View itself and we
found this being an average case of development.
//VIEW
onLogin(String userId, String password){
loginController.doLogin(userId, password){
dataManager.verifyLogin(userId, password){
onSuccess(){ // INLINE CODE TO SHOW SUCCESS }
onFailure(){ // INLINE CODE TO SHOW FAILURE }
} } }
M V & Controller
And so following being a rule in MVC for to solve the problem statement
Action in the View(Activity/Fragment)
-> Call to Controller
-> Controller Logic
-> Controller returns the View.
-where in last step, there is no restriction to let the View handle the result.
-Also the controllers are not restricted to be used for single view and can be shared among
multiple views
MVC: Flow Diagram
Following is the flow diagram in MVC
-Note: Image has been taken from internet
MVC: Interaction
Following is the interaction flow in MVC
-Note: Image has been taken from internet
Solution
Design Pattern: MVP
M V & Presenter
Consider the case with a LoginPresenter and same method
LoginController{
doLogin(String userId, String password){
//PERFORM OPERATION FOR PROCESSING THE LOGIN DETAIL
//ACT ON OR DELEGATE RESULT TO VIEW VIA A CONTRACT/INTERFACE
}
M V & Presenter
Now, integration of LoginPresenter with View requires the View to implement the CONTRACT/INTERFACE
defined to process the result delegated from Presenter
//VIEW
onLogin(String userId, String password){
loginPresenter..doLogin(userId, password);
}
onSuccess(){ //THE CONTRACT METHOD FOR LOGIN FROM INTERFACE}
onFailure(){ //THE CONTRACT METHOD FOR LOGIN FROM INTERFACE}
M V & Presenter
Action in the View(Activity/Fragment)
-> Notify to Presenter
- Presenter Logic
<- Revert back to update the View.
-where in last step, there is a restriction to let the View handle the result avoiding chances of
developers writing the inline code in View.
-90% of Presenter are having a 1-on-1 relation with View, and in very complex requirement, it
gets shared when needed.
MVP: Flow Diagram
Following is the flow diagram in MVP
-Note: Image has been taken from internet
MVP: Interaction
Following is the interaction flow in MVP
-Note: Image has been taken from internet
Solution
Design Pattern: MVVM
M V & ViewModel
ViewModel remains same as the Presenter but it gets implemented with 2-way DataBinding
Data binding : It is the process that binds the View with business logic lying at ViewModel layer. Android
comes with DataBinding Library to serve this purpose. If the binding is correctly set, then, when the data
changes its value, the elements that are bound to the data reflect changes automatically releasing the load of
ViewModel to delegate results each time.
Presenters, in MVP, can also use DataBinding making them tend towards MVVM and when it is done with 2-way
binding, it becomes MVVM.
M V & ViewModel
Following being a rule in MVVM
Action in the View(Activity/Fragment)
- Bound with ViewModel
- ViewModel Logic
- Revert back to notify the View, if required
MVVM: Flow Diagram
Following is the interaction flow in MVVM
-Note: Image has been taken from internet
Which one is better?
There is no wrong in using any of the patterns, but to reduce code and restrict your developer
making mistakes, i would personally recommend to go for MVP with binding, somewhere 1-way
ans/or 2-way.
It depends on how best you can follow the rules and guidelines and how much your development
is vulnerable to violate the rules & guidelines
References
StarterKit-MVP This is a first version of mvp based baseline project. This is designed to create as a starter-kit
project for Android platform based on MVP, making it easier to develop project features/modules on top of it.
StarterKit-MVVM: This is a first version of mvvm based baseline project. This is designed to create as a starter-
kit project for Android platform based on MVVM, making it easier to develop project features/modules on top of
it.
Both Starter-Kit uses a network library wrapped on top of Retrofit named Networx.
Starter-Kit: This project contains mainly MVP and MVVM design pattern using Retrofit.It also has MVVM using
RxNetwork. The purpose of Starter-Kit is to create a baseline project based on making it easier to develop project
features/modules on top of it.
These are first version of baseline projects and feedback are invited for improving it further.
Thank You
Share your feedback to-
Email: inbox.jkumar@gmail.com
Twitter: twitbox_jkumar
LinkedIn: https://www.linkedin.com/in/connect2jkumar/

More Related Content

PPTX
Acrhitecture deisign pattern_MVC_MVP_MVVM
PPTX
Software design patterns ppt
PPTX
MVVM ( Model View ViewModel )
PPTX
MVVM with WPF
 
PPTX
Training: MVVM Pattern
PDF
Models used in iOS programming, with a focus on MVVM
PPTX
MVVM - Model View ViewModel
PDF
ReactiveCocoa - Functional Reactive Programming concepts in iOS
Acrhitecture deisign pattern_MVC_MVP_MVVM
Software design patterns ppt
MVVM ( Model View ViewModel )
MVVM with WPF
 
Training: MVVM Pattern
Models used in iOS programming, with a focus on MVVM
MVVM - Model View ViewModel
ReactiveCocoa - Functional Reactive Programming concepts in iOS

What's hot (20)

PPTX
Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
PDF
Large-Scale JavaScript Development
PPTX
MVVM Design Pattern NDC2009
PPT
Facade pattern
PPTX
Class 02 Objective C
PDF
PPTX
Facade Design Pattern
ODP
Software Patterns
PDF
jQquerysummit - Large-scale JavaScript Application Architecture
PPT
Design Patterns (Examples in .NET)
PDF
當ZK遇見Front-End
PPTX
Mobile App Architectures & Coding guidelines
PPT
Facade pattern
PPTX
Design pattern - Facade Pattern
PPTX
Facade Pattern
PPTX
Design pattern
PPTX
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
PPTX
Facade pattern presentation(.pptx)
PPTX
Mvvm basics
PDF
Presentation facade design pattern
Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Large-Scale JavaScript Development
MVVM Design Pattern NDC2009
Facade pattern
Class 02 Objective C
Facade Design Pattern
Software Patterns
jQquerysummit - Large-scale JavaScript Application Architecture
Design Patterns (Examples in .NET)
當ZK遇見Front-End
Mobile App Architectures & Coding guidelines
Facade pattern
Design pattern - Facade Pattern
Facade Pattern
Design pattern
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
Facade pattern presentation(.pptx)
Mvvm basics
Presentation facade design pattern
Ad

Viewers also liked (20)

PDF
Android (software) Design Pattern
PPTX
Design Pattern in Software Engineering
PDF
Architectural Design Concepts Approaches - كونسيبت التصميم المعمارى و الفكرة ...
PDF
How to Become a Thought Leader in Your Niche
PPT
10 strategy pattern
PPTX
How to build your own Hybrid JS Interface with Android?
PDF
Architecture Description Languages: An Overview
PDF
5 Steps To Clean Your Android Code
PPTX
ANDROID TRAINING IN CHENNAI
PPTX
Android notifications. testing guideline
PPSX
Facebook hiring 6.0
PDF
Device fragmentation vs clean code
PDF
Clean code on Android (Droidcon Dubai 2015)
PPTX
Strategy Pattern
PDF
8990 Holdings - COL Financial presentation
PDF
The Decorator Pattern
PDF
android design pattern
DOCX
W06.01 Summary Affordable Homes: Building mass housing in India
PPT
Software Design Patterns
PPTX
Design Patterns - 01 Introduction and Decorator Pattern
Android (software) Design Pattern
Design Pattern in Software Engineering
Architectural Design Concepts Approaches - كونسيبت التصميم المعمارى و الفكرة ...
How to Become a Thought Leader in Your Niche
10 strategy pattern
How to build your own Hybrid JS Interface with Android?
Architecture Description Languages: An Overview
5 Steps To Clean Your Android Code
ANDROID TRAINING IN CHENNAI
Android notifications. testing guideline
Facebook hiring 6.0
Device fragmentation vs clean code
Clean code on Android (Droidcon Dubai 2015)
Strategy Pattern
8990 Holdings - COL Financial presentation
The Decorator Pattern
android design pattern
W06.01 Summary Affordable Homes: Building mass housing in India
Software Design Patterns
Design Patterns - 01 Introduction and Decorator Pattern
Ad

Similar to Architectural Design Pattern: Android (20)

PPTX
Android DesignArchitectures.pptx
PPTX
Design patterns in android
PPTX
UI Design Patterns
PPTX
MVVM presentation
PPT
Design pattern in android
PDF
Model View Presenter For Android
PDF
Model View Presenter For Android
PPTX
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
PDF
Model View Presenter For Android
PPTX
Difference between Software Architectural pattern
PPTX
My perspective on MVP and architecture discussions
PPTX
MVP vs MVVM : a fast introduction
PPTX
Architectural Design & Patterns
PDF
How I Accidentally Discovered MVVM
DOCX
Mvc, mvp & mvvm (erp)
PPTX
Slide Presentation of MVP Pattern Concept
PDF
Ui design patterns
PDF
iOS architecture patterns
PPTX
Adopting MVVM
Android DesignArchitectures.pptx
Design patterns in android
UI Design Patterns
MVVM presentation
Design pattern in android
Model View Presenter For Android
Model View Presenter For Android
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
Model View Presenter For Android
Difference between Software Architectural pattern
My perspective on MVP and architecture discussions
MVP vs MVVM : a fast introduction
Architectural Design & Patterns
How I Accidentally Discovered MVVM
Mvc, mvp & mvvm (erp)
Slide Presentation of MVP Pattern Concept
Ui design patterns
iOS architecture patterns
Adopting MVVM

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Approach and Philosophy of On baking technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Big Data Technologies - Introduction.pptx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Cloud computing and distributed systems.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
Teaching material agriculture food technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Machine learning based COVID-19 study performance prediction
Approach and Philosophy of On baking technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Chapter 3 Spatial Domain Image Processing.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Dropbox Q2 2025 Financial Results & Investor Presentation
Big Data Technologies - Introduction.pptx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Cloud computing and distributed systems.
Building Integrated photovoltaic BIPV_UPV.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Teaching material agriculture food technology
Per capita expenditure prediction using model stacking based on satellite ima...

Architectural Design Pattern: Android

  • 3. What is Design Pattern In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.
  • 4. Need of Design Pattern? 1. To solve a recurring problem in software development 1. To represent a relationships between classes and objects with defined responsibilities to carry out the solution in a concrete way 1. To develop highly cohesive modules with minimal coupling
  • 6. Problem Statement Consider the following story - Story: As a user, i must be able to get a successful status so that i can find out whether user id and password given by me is correct or not. Model: UserInfo(userId, password) View: InputBox(userId), InputBox(password), actionButton Note: For the story above, Model and View will remain same and we will see how to implement them in MVC, MVP and MVVM.
  • 8. M V & Controller Consider designing a Login Controller with a method onLogin which will execute when login button gets clicked in View defined in problem statement LoginController{ doLogin(String userId, String password){ //PERFORM OPERATION FOR PROCESSING THE LOGIN DETAIL //ACT ON OR DELEGATE RESULT TO VIEW }
  • 9. M V & Controller Now, during the integration of LoginController with View, there is no mandatory rule to delegate result to View by using Java Interface and there may be chance that the result gets processed inline in View itself and we found this being an average case of development. //VIEW onLogin(String userId, String password){ loginController.doLogin(userId, password){ dataManager.verifyLogin(userId, password){ onSuccess(){ // INLINE CODE TO SHOW SUCCESS } onFailure(){ // INLINE CODE TO SHOW FAILURE } } } }
  • 10. M V & Controller And so following being a rule in MVC for to solve the problem statement Action in the View(Activity/Fragment) -> Call to Controller -> Controller Logic -> Controller returns the View. -where in last step, there is no restriction to let the View handle the result. -Also the controllers are not restricted to be used for single view and can be shared among multiple views
  • 11. MVC: Flow Diagram Following is the flow diagram in MVC -Note: Image has been taken from internet
  • 12. MVC: Interaction Following is the interaction flow in MVC -Note: Image has been taken from internet
  • 14. M V & Presenter Consider the case with a LoginPresenter and same method LoginController{ doLogin(String userId, String password){ //PERFORM OPERATION FOR PROCESSING THE LOGIN DETAIL //ACT ON OR DELEGATE RESULT TO VIEW VIA A CONTRACT/INTERFACE }
  • 15. M V & Presenter Now, integration of LoginPresenter with View requires the View to implement the CONTRACT/INTERFACE defined to process the result delegated from Presenter //VIEW onLogin(String userId, String password){ loginPresenter..doLogin(userId, password); } onSuccess(){ //THE CONTRACT METHOD FOR LOGIN FROM INTERFACE} onFailure(){ //THE CONTRACT METHOD FOR LOGIN FROM INTERFACE}
  • 16. M V & Presenter Action in the View(Activity/Fragment) -> Notify to Presenter - Presenter Logic <- Revert back to update the View. -where in last step, there is a restriction to let the View handle the result avoiding chances of developers writing the inline code in View. -90% of Presenter are having a 1-on-1 relation with View, and in very complex requirement, it gets shared when needed.
  • 17. MVP: Flow Diagram Following is the flow diagram in MVP -Note: Image has been taken from internet
  • 18. MVP: Interaction Following is the interaction flow in MVP -Note: Image has been taken from internet
  • 20. M V & ViewModel ViewModel remains same as the Presenter but it gets implemented with 2-way DataBinding Data binding : It is the process that binds the View with business logic lying at ViewModel layer. Android comes with DataBinding Library to serve this purpose. If the binding is correctly set, then, when the data changes its value, the elements that are bound to the data reflect changes automatically releasing the load of ViewModel to delegate results each time. Presenters, in MVP, can also use DataBinding making them tend towards MVVM and when it is done with 2-way binding, it becomes MVVM.
  • 21. M V & ViewModel Following being a rule in MVVM Action in the View(Activity/Fragment) - Bound with ViewModel - ViewModel Logic - Revert back to notify the View, if required
  • 22. MVVM: Flow Diagram Following is the interaction flow in MVVM -Note: Image has been taken from internet
  • 23. Which one is better? There is no wrong in using any of the patterns, but to reduce code and restrict your developer making mistakes, i would personally recommend to go for MVP with binding, somewhere 1-way ans/or 2-way. It depends on how best you can follow the rules and guidelines and how much your development is vulnerable to violate the rules & guidelines
  • 24. References StarterKit-MVP This is a first version of mvp based baseline project. This is designed to create as a starter-kit project for Android platform based on MVP, making it easier to develop project features/modules on top of it. StarterKit-MVVM: This is a first version of mvvm based baseline project. This is designed to create as a starter- kit project for Android platform based on MVVM, making it easier to develop project features/modules on top of it. Both Starter-Kit uses a network library wrapped on top of Retrofit named Networx. Starter-Kit: This project contains mainly MVP and MVVM design pattern using Retrofit.It also has MVVM using RxNetwork. The purpose of Starter-Kit is to create a baseline project based on making it easier to develop project features/modules on top of it. These are first version of baseline projects and feedback are invited for improving it further.
  • 25. Thank You Share your feedback to- Email: inbox.jkumar@gmail.com Twitter: twitbox_jkumar LinkedIn: https://www.linkedin.com/in/connect2jkumar/