SlideShare a Scribd company logo
Android Design Architectures
 When developers work on a real mobile application whose nature is dynamic and
will expand its features according to the user’s need, then it is not possible to write
core logic in activities or fragments.
 To structure the project’s code and to give it a modular design(separated code
parts), architecture patterns are applied to separate the concerns.
 The most popular android architectures used by developers are the following:
 MVC (Model — View — Controller)
 MVP (Model — View — Presenter)
 MVVM (Model — View — ViewModel)
 The main idea of all these patterns is to organize the project in a proper way so
that all the codes get covered in the Unit Testing.
 Moreover, it is very helpful in the maintenance of the software, to add and remove
features and developers can keep a track of various crucial logic parts.
1.Model View Controller(Standard Android)
 It is the "default" approach with layout files,Activities/Fragments acting as the
controller and Models used for data and persistence
 With this approach, Activities are in charge of processing the data and updating
the views.
 Activities act like a controller in MVC but with some extra responsibilities that
should be part of the view.
 The problem with this standard architecture is that Activities and Fragments can
become quite large and very difficult to test.
2.Model View Presenter(Model View Presenter)
 When using MVP, Activities and Fragments become part of the view layer and they
delegate most of the work to presenter objects.
 Each Activity has a matching presenter that handles all access to the model.
 The presenters also notify the Activities when the data is ready to display.
3.Model-View-ViewModel(Data-binding MVVM)
 ViewModels retrieve data from the model when requested from the view via the
Android data binding framework.
 With this pattern, Activities and Fragments become very lightweight.
 Moreover, writing unit tests becomes easier because the ViewModels are
decoupled from the view.
MVC-Model View Controller
 Developing an android application by applying a software architecture
pattern is always preferred by the developers.
 An architecture pattern gives modularity to the project files and assures that
all the codes get covered in Unit testing.
 It makes the task easy for developers to maintain the software and to expand
the features of the application in the future.
 There are some architectures that are very popular among developers and
one of them is the Model—View—Controller(MVC) Pattern.
 The MVC pattern suggests splitting the code into 3 components.
 While creating the class/file of the application, the developer must categorize it
into one of the following three layers:
 Model:
 This component stores the application data.
 It has no knowledge about the interface.
 The model is responsible for handling the domain logic(real-world business rules) and
communication with the database and network layers.
 View:
 It is the UI(User Interface) layer that holds components that are visible on the screen.
 Moreover, it provides the visualization of the data stored in the Model and offers interaction to
the user.
 Controller:
 This component establishes the relationship between the View and the Model.
 It contains the core application logic and gets informed of the user’s behavior and updates the
Model as per the need.
 In spite of applying MVC schema to give a modular design to the
application, code layers do depend on each other.
 In this pattern, View and Controller both depend upon the Model.
 Multiple approaches are possible to apply the MVC pattern in the project:
 Approach 1: Activities and fragments can perform the role of Controller and
responsible for updating the View.
 Approach 2: Use activity or fragments as views and controller while Model will
be a separate class that does not extend any Android class.
 In MVC architecture, application data is updated by the controller and
View gets the data.
 Since the Model component is separated, it could be tested
independently of the UI.
 Further, if the View layer respects the single responsibility principle
then their role is just to update the Controller for every user event and just
display data from the Model, without implementing any business logic.
 In this case, UI tests should be enough to cover the functionalities of the
View.
Example of MVC Architecture
 To understand the implementation of the MVC architecture pattern more
clearly, here is a simple example of an android application.
 This application will have 3 buttons and each one of them displays the
count that how many times the user has clicked that particular button.
 To develop this application the code has been separated in the following
manner:
 Controller and View will be handled by the Activity. Whenever the user clicks
the buttons, activity directs the Model to handle the further operations. The
activity will act as an observer.
 The Model will be a separate class that contains the data to be displayed. The
operations on the data will be performed by functions of this class and after
updating the values of the data this Observable class notifies the
Observer(Activity) about the change.
Advantages of MVC architecture pattern
 MVC pattern increases the code testability and makes it easier to
implement new features as it highly supports the separation of concerns.
 Unit testing of Model and Controller is possible as they do not extend or
use any Android class.
 Functionalities of the View can be checked through UI tests if the View
respect the single responsibility principle(update controller and display
data from the model without implementing domain logic)
Disadvantages of MVC architecture pattern
 Code layers depend on each other even if MVC is applied
correctly.
 No parameter to handle UI logic i.e., how to display the data.
Model—View—Presenter(MVP) Pattern
 MVP pattern is the second iteration of Android app architecture.
 This pattern is widely accepted and is still recommended for
upcoming developers.
 The purpose of each component is easy to learn:
 Model: Layer for storing data. It is responsible for handling the domain
logic(real-world business rules) and communication with the database and
network layers.
 View: UI(User Interface) layer. It provides the visualization of the data and
keep a track of the user’s action in order to notify the Presenter.
 Presenter: Fetch the data from the model and applies the UI logic to
decide what to display. It manages the state of the View and takes actions
according to the user’s input notification from the View.
 In the MVP schema, View and Presenter are closely related and have a reference to
each other.
 To make the code readable and easier to understand, a Contract interface class is
used to define the Presenter and View relationship.
 The View is abstracted and has an interface in order to enable the Presenter for
Unit Testing.
 In the initial stages of Android development, learners do write codes in
such a manner that eventually creates a MainActivity class which contains
all the implementation logic(real-world business logic) of the application.
 This approach of app development leads to Android activity gets closely
coupled to both UI and the application data processing mechanism.
 Further, it causes difficulties in the maintenance and scaling of such
mobile applications.
 To avoid such problems in maintainability, readability, scalability, and
refactoring of applications, developers prefer to define well-separated
layers of code
 By applying software architecture patterns, one can organize the code of
the application to separate the concerns.
 MVP (Model — View — Presenter) architecture is one of the most
architecture patterns and is valid in organizing the project.
 Most of the core business logic resides in Controller. During the lifetime of an
application, this file grows bigger and it becomes difficult to maintain the code.
 Because of tightly-coupled UI and data access mechanisms, both Controller and
View layer falls in the same activity or fragment. This cause problem in making
changes in the features of the application.
 It becomes hard to carry out Unit testing of the different layer as most of the part
which are under testing needs Android SDK components.
 Key Points of MVP Architecture
 Communication between View-Presenter and Presenter-Model happens via an
interface(also called Contract).
 One Presenter class manages one View at a time i.e., there is a one-to-one
relationship between Presenter and View.
 Model and View class doesn’t have knowledge about each other’s existence.
 Advantages:
 No conceptual relationship in android components
 Easy code maintenance and testing as the application’s model, view, and presenter layer
are separated.
 Disadvantages:
 If the developer does not follow the single responsibility principle to break the code then
the Presenter layer tends to expand to a huge all-knowing class.
The Model—View—ViewModel (MVVM) Pattern
 The third iteration of android architecture is the MVVV pattern.
 While releasing the Android Architecture Components, the Android team
recommended this architecture pattern. Below are the separate code layers:
 Model: This layer is responsible for the abstraction of the data sources. Model and
ViewModel work together to get and save the data.
 View: The purpose of this layer is to inform the ViewModel about the user’s action.
 ViewModel: It exposes those data streams which are relevant to the View.
 The MVVM and MVP patterns are quite similar because both are efficient in
abstracting the state and behavior of the View layer.
 In MVVM, Views can bind itself to the data streams which are exposed by
ViewModel.
 In MVVM schema the View informs the ViewModel about various actions.
 The View has a reference to the ViewModel while ViewModel has no
information about the View.
 The many-to-one relationship that exists between View and ViewModel
and MVVM supports two-way data binding between both.
 Developers always prefer a clean and structured code for the projects.
 By organizing the codes according to a design pattern helps in the maintenance of
the software.
 By having knowledge of all crucial logic parts of the android application, it is easier
to add and remove app features.
 Further, design patterns also assure that all the codes get covered in Unit Testing
without the interference of other classes.
 Model — View — ViewModel (MVVM) is the industry-recognized software
architecture pattern that overcomes all drawbacks of MVP and MVC design
patterns.
 MVVM suggests separating the data presentation logic(Views or UI) from the core
business logic part of the application.
 MVVM pattern has some similarities with the MVP(Model — View —
Presenter) design pattern as the Presenter role is played by ViewModel.
 However, the drawbacks of the MVP pattern has been solved by MVVM in
the following ways:
 ViewModel does not hold any kind of reference to the View.
 Many to 1 relationship exist between View and ViewModel.
 No triggering methods to update the View.
Ways to Implement MVVM in the Project
 There are 2 ways to implement MVVM design pattern in Android projects:
 Using the DataBinding library released by Google
 Using any tool like RxJava for DataBinding.
 Data Binding:
 Google releases the Data Binding Library for Android that allows the developers to bind UI
components in the XML layouts with the application’s data repositories.
 This helps in minimizing the code of core application logic that binds with View.
 Further, Two – way Data Binding is done for binding the objects to the XML layouts so that
object and the layout both can send data to each other.
Syntax for the two way data binding is @={variable}
 Advantages of Architecture
 Developers can design applications that can accept changes in the future.
 Gives a modular design to the application which assures good quality testing and
maintenance of code.
 Disadvantages of Architecture
 Writing the whole project code in an architecture pattern is a time taking process.
 Strict discipline is required from the developer team side as one misplaced change can
ruin the integrity of the architecture.
Thank you

More Related Content

Similar to Android DesignArchitectures.pptx

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
naral
 
Lecture10 oopj
Lecture10 oopjLecture10 oopj
Lecture10 oopj
Dhairya Joshi
 
IntroductionToMVC
IntroductionToMVCIntroductionToMVC
IntroductionToMVC
Akhil Mittal
 
MVC
MVCMVC
MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )
Ahmed Emad
 
mvc development company in UK.
mvc development company in UK.mvc development company in UK.
mvc development company in UK.
Techrishblogger
 
MVVM presentation
MVVM presentationMVVM presentation
MVVM presentation
Inova LLC
 
MVC
MVCMVC
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC Structure
Dipika Wadhvani
 
Mvc Architecture in a web based application
Mvc Architecture in a web based applicationMvc Architecture in a web based application
Mvc Architecture in a web based application
OnGraph Technologies Pvt. Ltd.
 
Code Camp 06 Model View Presenter Architecture
Code Camp 06   Model View Presenter ArchitectureCode Camp 06   Model View Presenter Architecture
Code Camp 06 Model View Presenter Architecture
bitburner93
 
demystifying_the_architectures_of_a_mobile_app_development.pptx
demystifying_the_architectures_of_a_mobile_app_development.pptxdemystifying_the_architectures_of_a_mobile_app_development.pptx
demystifying_the_architectures_of_a_mobile_app_development.pptx
sarah david
 
Design Pattern
Design PatternDesign Pattern
Design Pattern
Pawan Kumar Tiwari
 
Design pattern
Design patternDesign pattern
Design pattern
Pawan Kumar Tiwari
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
Wayne Tun Myint
 
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
Andrei Popa
 
demystifying_the_architectures_of_a_mobile_app_development.pdf
demystifying_the_architectures_of_a_mobile_app_development.pdfdemystifying_the_architectures_of_a_mobile_app_development.pdf
demystifying_the_architectures_of_a_mobile_app_development.pdf
sarah david
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
Jitendra Kumar
 
mvc development company in UK
mvc development company in UKmvc development company in UK
mvc development company in UK
Techrishblogger
 
SUE AGILE MVVM (English)
SUE AGILE MVVM (English)SUE AGILE MVVM (English)
SUE AGILE MVVM (English)
Sabino Labarile
 

Similar to Android DesignArchitectures.pptx (20)

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
 
Lecture10 oopj
Lecture10 oopjLecture10 oopj
Lecture10 oopj
 
IntroductionToMVC
IntroductionToMVCIntroductionToMVC
IntroductionToMVC
 
MVC
MVCMVC
MVC
 
MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )
 
mvc development company in UK.
mvc development company in UK.mvc development company in UK.
mvc development company in UK.
 
MVVM presentation
MVVM presentationMVVM presentation
MVVM presentation
 
MVC
MVCMVC
MVC
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC Structure
 
Mvc Architecture in a web based application
Mvc Architecture in a web based applicationMvc Architecture in a web based application
Mvc Architecture in a web based application
 
Code Camp 06 Model View Presenter Architecture
Code Camp 06   Model View Presenter ArchitectureCode Camp 06   Model View Presenter Architecture
Code Camp 06 Model View Presenter Architecture
 
demystifying_the_architectures_of_a_mobile_app_development.pptx
demystifying_the_architectures_of_a_mobile_app_development.pptxdemystifying_the_architectures_of_a_mobile_app_development.pptx
demystifying_the_architectures_of_a_mobile_app_development.pptx
 
Design Pattern
Design PatternDesign Pattern
Design Pattern
 
Design pattern
Design patternDesign pattern
Design pattern
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
 
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
 
demystifying_the_architectures_of_a_mobile_app_development.pdf
demystifying_the_architectures_of_a_mobile_app_development.pdfdemystifying_the_architectures_of_a_mobile_app_development.pdf
demystifying_the_architectures_of_a_mobile_app_development.pdf
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
mvc development company in UK
mvc development company in UKmvc development company in UK
mvc development company in UK
 
SUE AGILE MVVM (English)
SUE AGILE MVVM (English)SUE AGILE MVVM (English)
SUE AGILE MVVM (English)
 

Recently uploaded

Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 

Recently uploaded (20)

Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 

Android DesignArchitectures.pptx

  • 2.  When developers work on a real mobile application whose nature is dynamic and will expand its features according to the user’s need, then it is not possible to write core logic in activities or fragments.  To structure the project’s code and to give it a modular design(separated code parts), architecture patterns are applied to separate the concerns.  The most popular android architectures used by developers are the following:  MVC (Model — View — Controller)  MVP (Model — View — Presenter)  MVVM (Model — View — ViewModel)  The main idea of all these patterns is to organize the project in a proper way so that all the codes get covered in the Unit Testing.  Moreover, it is very helpful in the maintenance of the software, to add and remove features and developers can keep a track of various crucial logic parts.
  • 3.
  • 4. 1.Model View Controller(Standard Android)  It is the "default" approach with layout files,Activities/Fragments acting as the controller and Models used for data and persistence  With this approach, Activities are in charge of processing the data and updating the views.  Activities act like a controller in MVC but with some extra responsibilities that should be part of the view.  The problem with this standard architecture is that Activities and Fragments can become quite large and very difficult to test.
  • 5. 2.Model View Presenter(Model View Presenter)  When using MVP, Activities and Fragments become part of the view layer and they delegate most of the work to presenter objects.  Each Activity has a matching presenter that handles all access to the model.  The presenters also notify the Activities when the data is ready to display.
  • 6. 3.Model-View-ViewModel(Data-binding MVVM)  ViewModels retrieve data from the model when requested from the view via the Android data binding framework.  With this pattern, Activities and Fragments become very lightweight.  Moreover, writing unit tests becomes easier because the ViewModels are decoupled from the view.
  • 8.  Developing an android application by applying a software architecture pattern is always preferred by the developers.  An architecture pattern gives modularity to the project files and assures that all the codes get covered in Unit testing.  It makes the task easy for developers to maintain the software and to expand the features of the application in the future.  There are some architectures that are very popular among developers and one of them is the Model—View—Controller(MVC) Pattern.
  • 9.  The MVC pattern suggests splitting the code into 3 components.  While creating the class/file of the application, the developer must categorize it into one of the following three layers:  Model:  This component stores the application data.  It has no knowledge about the interface.  The model is responsible for handling the domain logic(real-world business rules) and communication with the database and network layers.  View:  It is the UI(User Interface) layer that holds components that are visible on the screen.  Moreover, it provides the visualization of the data stored in the Model and offers interaction to the user.  Controller:  This component establishes the relationship between the View and the Model.  It contains the core application logic and gets informed of the user’s behavior and updates the Model as per the need.
  • 10.
  • 11.  In spite of applying MVC schema to give a modular design to the application, code layers do depend on each other.  In this pattern, View and Controller both depend upon the Model.  Multiple approaches are possible to apply the MVC pattern in the project:  Approach 1: Activities and fragments can perform the role of Controller and responsible for updating the View.  Approach 2: Use activity or fragments as views and controller while Model will be a separate class that does not extend any Android class.
  • 12.  In MVC architecture, application data is updated by the controller and View gets the data.  Since the Model component is separated, it could be tested independently of the UI.  Further, if the View layer respects the single responsibility principle then their role is just to update the Controller for every user event and just display data from the Model, without implementing any business logic.  In this case, UI tests should be enough to cover the functionalities of the View.
  • 13. Example of MVC Architecture  To understand the implementation of the MVC architecture pattern more clearly, here is a simple example of an android application.  This application will have 3 buttons and each one of them displays the count that how many times the user has clicked that particular button.  To develop this application the code has been separated in the following manner:  Controller and View will be handled by the Activity. Whenever the user clicks the buttons, activity directs the Model to handle the further operations. The activity will act as an observer.  The Model will be a separate class that contains the data to be displayed. The operations on the data will be performed by functions of this class and after updating the values of the data this Observable class notifies the Observer(Activity) about the change.
  • 14. Advantages of MVC architecture pattern  MVC pattern increases the code testability and makes it easier to implement new features as it highly supports the separation of concerns.  Unit testing of Model and Controller is possible as they do not extend or use any Android class.  Functionalities of the View can be checked through UI tests if the View respect the single responsibility principle(update controller and display data from the model without implementing domain logic)
  • 15. Disadvantages of MVC architecture pattern  Code layers depend on each other even if MVC is applied correctly.  No parameter to handle UI logic i.e., how to display the data.
  • 17.  MVP pattern is the second iteration of Android app architecture.  This pattern is widely accepted and is still recommended for upcoming developers.  The purpose of each component is easy to learn:  Model: Layer for storing data. It is responsible for handling the domain logic(real-world business rules) and communication with the database and network layers.  View: UI(User Interface) layer. It provides the visualization of the data and keep a track of the user’s action in order to notify the Presenter.  Presenter: Fetch the data from the model and applies the UI logic to decide what to display. It manages the state of the View and takes actions according to the user’s input notification from the View.
  • 18.
  • 19.  In the MVP schema, View and Presenter are closely related and have a reference to each other.  To make the code readable and easier to understand, a Contract interface class is used to define the Presenter and View relationship.  The View is abstracted and has an interface in order to enable the Presenter for Unit Testing.
  • 20.  In the initial stages of Android development, learners do write codes in such a manner that eventually creates a MainActivity class which contains all the implementation logic(real-world business logic) of the application.  This approach of app development leads to Android activity gets closely coupled to both UI and the application data processing mechanism.  Further, it causes difficulties in the maintenance and scaling of such mobile applications.  To avoid such problems in maintainability, readability, scalability, and refactoring of applications, developers prefer to define well-separated layers of code  By applying software architecture patterns, one can organize the code of the application to separate the concerns.  MVP (Model — View — Presenter) architecture is one of the most architecture patterns and is valid in organizing the project.
  • 21.  Most of the core business logic resides in Controller. During the lifetime of an application, this file grows bigger and it becomes difficult to maintain the code.  Because of tightly-coupled UI and data access mechanisms, both Controller and View layer falls in the same activity or fragment. This cause problem in making changes in the features of the application.  It becomes hard to carry out Unit testing of the different layer as most of the part which are under testing needs Android SDK components.
  • 22.  Key Points of MVP Architecture  Communication between View-Presenter and Presenter-Model happens via an interface(also called Contract).  One Presenter class manages one View at a time i.e., there is a one-to-one relationship between Presenter and View.  Model and View class doesn’t have knowledge about each other’s existence.
  • 23.  Advantages:  No conceptual relationship in android components  Easy code maintenance and testing as the application’s model, view, and presenter layer are separated.  Disadvantages:  If the developer does not follow the single responsibility principle to break the code then the Presenter layer tends to expand to a huge all-knowing class.
  • 25.  The third iteration of android architecture is the MVVV pattern.  While releasing the Android Architecture Components, the Android team recommended this architecture pattern. Below are the separate code layers:  Model: This layer is responsible for the abstraction of the data sources. Model and ViewModel work together to get and save the data.  View: The purpose of this layer is to inform the ViewModel about the user’s action.  ViewModel: It exposes those data streams which are relevant to the View.  The MVVM and MVP patterns are quite similar because both are efficient in abstracting the state and behavior of the View layer.  In MVVM, Views can bind itself to the data streams which are exposed by ViewModel.
  • 26.
  • 27.  In MVVM schema the View informs the ViewModel about various actions.  The View has a reference to the ViewModel while ViewModel has no information about the View.  The many-to-one relationship that exists between View and ViewModel and MVVM supports two-way data binding between both.
  • 28.  Developers always prefer a clean and structured code for the projects.  By organizing the codes according to a design pattern helps in the maintenance of the software.  By having knowledge of all crucial logic parts of the android application, it is easier to add and remove app features.  Further, design patterns also assure that all the codes get covered in Unit Testing without the interference of other classes.  Model — View — ViewModel (MVVM) is the industry-recognized software architecture pattern that overcomes all drawbacks of MVP and MVC design patterns.  MVVM suggests separating the data presentation logic(Views or UI) from the core business logic part of the application.
  • 29.  MVVM pattern has some similarities with the MVP(Model — View — Presenter) design pattern as the Presenter role is played by ViewModel.  However, the drawbacks of the MVP pattern has been solved by MVVM in the following ways:  ViewModel does not hold any kind of reference to the View.  Many to 1 relationship exist between View and ViewModel.  No triggering methods to update the View.
  • 30. Ways to Implement MVVM in the Project  There are 2 ways to implement MVVM design pattern in Android projects:  Using the DataBinding library released by Google  Using any tool like RxJava for DataBinding.  Data Binding:  Google releases the Data Binding Library for Android that allows the developers to bind UI components in the XML layouts with the application’s data repositories.  This helps in minimizing the code of core application logic that binds with View.  Further, Two – way Data Binding is done for binding the objects to the XML layouts so that object and the layout both can send data to each other. Syntax for the two way data binding is @={variable}
  • 31.  Advantages of Architecture  Developers can design applications that can accept changes in the future.  Gives a modular design to the application which assures good quality testing and maintenance of code.  Disadvantages of Architecture  Writing the whole project code in an architecture pattern is a time taking process.  Strict discipline is required from the developer team side as one misplaced change can ruin the integrity of the architecture.