SlideShare a Scribd company logo
1 of 23
Download to read offline
Android - Model
Architecture
Indonesia
Mar 2016
Fandy Gotama
2
Security
3
Security: HTTPS
- Always use HTTPS,
- Pay attention to TLS version supported by Android API,
- Do coordinate with the Phone Provider,
- Small user might experience slowness, expect bad
review.
4
Security: Securing your API
- OAuth,
- HTTP Basic Authentication,
- API Key.
5
Networking best practices
6
Networking best practices
- Don’t build your own custom http, use libraries,
- Always use timeout,
- Use Jackson library to parse JSON data to POJO,
- Always cache your data (including images),
- Pay attention to your activity / fragment lifecycle.
7
MVP
Model Architecture
Model Diagrams
OlxService
CommunicationImpl
Communication
Interface
APIDataSource StorageDataSource
Repositories
Pattern
Storage
DataSource Interface
DataStoreFactory
9
Model Architecture
- Using repository pattern,
- Repository encapsulated set of objects in data store,
- Clean separation, and one way dependency between
presenter and model layer.
10
Model Breakdown
11
Repository Implementation
- In charge for getting data requested by presenter.
12
Repository Class
public class ShoppingRepositoryImpl {
private final ShoppingDataStoreFactory mFactory;
public ShoppingRepositoryImpl(@NonNull ShoppingDataStoreFactory factory) {
mFactory = factory;
}
public Shopping getShopping(ShoppingRequest request) {
return mFactory.getDataStore().getShopping(request);
}
}
13
DataStoreFactory
- An abstract class, has a job to get data from cache or
from API,
- Repository will call getDataStore() method get the data.
14
public abstract class DataStoreFactory<T extends DataStore> {
public T getDataStore() {
DataStore dataStore;
if (isCacheAvailable()) {
dataStore = createDiskDataStore(mResponseCache);
} else {
dataStore = createApiDataStore(mResponseCache);
}
return (T) dataStore;
}
protected abstract T createDiskDataStore(ResponseCache responseCache);
protected abstract T createApiDataStore(ResponseCache responseCache);
DataStoreFactory: Abstract Class
15
DataStoreFactory: Implementation Class
public class ShoppingDataStoreFactory extends
DataStoreFactory<ShoppingDataStore> {
@Override
protected ShoppingDataStore createDiskDataStore(ResponseCache
responseCache) {
return new ShoppingDiskDataStore(responseCache);
}
@Override
protected ShoppingDataStore createApiDataStore(ResponseCache
responseCache) {
return new ShoppingApiDataStore(mService, responseCache);
}
}
16
ShoppingApiDataStore
- Called by DataStoreFactory to get the data from API,
- This class will connect to API using retrofit, and insert
the data into cache.
17
ShoppingApiDataStore Class
public class ShoppingApiDataStore implements ShoppingDataStore {
@Override
public Shopping getShopping(ShoppingRequest request) {
Shopping shopping = mService.shopping(
request.callname,
RESONSE_ENCODING,
APP_ID,
SITE_ID,
request.keywords,
VERSION);
mResponseCache.putList(shopping);
return shopping;
}
}
18
ShoppingDiskDataStore
- Called by DataStoreFactory to get the data from disk,
- This class will get the data from disk (can be mysql, file
system or memory).
19
ShoppingDiskDataStore Class
public class ShoppingDiskDataStore implements ShoppingDataStore {
private final ResponseCache<Shopping, ShoppingRequest> mResponseCache;
public ShoppingDiskDataStore(@NonNull ResponseCache responseCache) {
mResponseCache = responseCache;
}
@Override
public Shopping getShopping(@NonNull ShoppingRequest request) {
return mResponseCache.getList(request);
}
}
20
In Summary
- Repository pattern is abstraction, reduce complexity and
make the rest of the code persistent ignorant,
- Easy to write unit test.
21
Source Code
https://github.com/CommunityShareCode/MVP
22
References
- http://mashable.com/2011/05/31/https-web-security/#QBT1U2DL5sqp
- http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/
- http://martinfowler.com/eaaCatalog/repository.html
- https://github.com/futurice/android-best-practices
- https://www.nngroup.com/articles/website-response-times/
23
Q&A

More Related Content

Similar to Android - Model Architecture

TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
Nuno Godinho
 
Storage Plug-ins
Storage Plug-ins Storage Plug-ins
Storage Plug-ins
buildacloud
 
Java Technology
Java TechnologyJava Technology
Java Technology
ifnu bima
 

Similar to Android - Model Architecture (20)

Jetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedJetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO Extended
 
Open sourcing the store
Open sourcing the storeOpen sourcing the store
Open sourcing the store
 
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9
 
Microsoft Windows Server AppFabric
Microsoft Windows Server AppFabricMicrosoft Windows Server AppFabric
Microsoft Windows Server AppFabric
 
Spring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenSpring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in Heaven
 
Solid fire cloudstack storage overview - CloudStack European User Group
Solid fire cloudstack storage overview - CloudStack European User GroupSolid fire cloudstack storage overview - CloudStack European User Group
Solid fire cloudstack storage overview - CloudStack European User Group
 
CloudStack Meetup London - Primary Storage Presentation by SolidFire
CloudStack Meetup London - Primary Storage Presentation by SolidFire CloudStack Meetup London - Primary Storage Presentation by SolidFire
CloudStack Meetup London - Primary Storage Presentation by SolidFire
 
datastore_devfest2020_incheon
datastore_devfest2020_incheondatastore_devfest2020_incheon
datastore_devfest2020_incheon
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
 
Storage Plug-ins
Storage Plug-ins Storage Plug-ins
Storage Plug-ins
 
CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara
 
Presentation of OrientDB v2.2 - Webinar
Presentation of OrientDB v2.2 - WebinarPresentation of OrientDB v2.2 - Webinar
Presentation of OrientDB v2.2 - Webinar
 
Java Technology
Java TechnologyJava Technology
Java Technology
 
Apache Eagle in Action
Apache Eagle in ActionApache Eagle in Action
Apache Eagle in Action
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Practical OData
Practical ODataPractical OData
Practical OData
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
 
Spring Data in 10 minutes
Spring Data in 10 minutesSpring Data in 10 minutes
Spring Data in 10 minutes
 
The new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfileThe new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfile
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Android - Model Architecture