SlideShare a Scribd company logo
1 of 24
Download to read offline
§
How we are architecting Android at
Taxibeat… the clean way.
Michael Bakogiannis

Android Software Engineer

@bakoproductions
Once upon a time…
Once upon a time…
• Driver and passenger apps started as two
simple projects with the goal of providing an
easy transportation platform for the people
• There was a basic structure and some simple
features
• The need for expanding on different markets
and tense competition forced quick changes to
this structure making the code complex
Complex meaning…
• God Activities
• Humongous helper/manager classes that became extra
sophisticated
• Legacy code
• The code responsible for providing the UX
(business rules) was tightly coupled with the
code responsible for the UI
App Redesign
• A new architecture should be able to:
• separate UI from UX
• let as develop and debug faster
• let as code on the same “activity” at the same time with the least
of conflicts
• provide a set of rules that new members of the team should follow
so as to learn the codebase faster
• be test friendly
• A pattern like MVP was not enough
Clean architecture to the rescue
Clean architecture to the
rescue
• It is not a pattern like MVP
• It is a set of rules in order to create a layered
approach. These layers are able to separate
the platform specific code from the business
rules
I want you to think of your application as a group of use
cases that describe the intent of the application and a
group of plugins that give those use cases access to the
outside world. 

Robert C Martin “Uncle Bob”
Dependency Rule
Dependencies should
only point inwards
An inner circle should not
know anything about an
outer circle.
Our Approach
Presentation
Layer
MVP Pattern
Domain
Layer
Business
Models
Data Layer
Repository
Pattern
Interactors(UseCases)
Datasources
Read also here: https://github.com/android10/Android-CleanArchitecture
Presentation Layer
• This layer provides the UI and a great deal of the UX
to the user
Android
Component
Presenter
Screen
Interface
• Android Components are the
Activities, Services,
Fragments, Notifications
etc…
• The Screen is an Interface
that defines the methods
that the Android Component
should implement
• The Presenter provides the
business logic
Read also here: https://medium.com/taxibeat/android-architecture-with-multi-screen-
mvp-46d3ccafa7b9
Presentation Layer in practise
public class ExampleActivity extends AppCompatActivity
implements ExampleScreen {

private ExamplePresenter presenter;



@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.act_example);

presenter = new ExamplePresenter(this);

presenter.initialize();

}



@Override

public void showLoading() { /* Actual Implementation */ }



@Override

public void hideLoading() { /* Actual Implementation */ }


@Override

public void showData(Data data) { /* Actual Implementation */ }



@Override

public void showError(String error) { /* Actual Implementation */ }


}
public interface ExampleScreen {

void showLoading();



void hideLoading();



void showData(Data data);



void showError(String error);

}
The screen does not
know who implements
its methods
It may be an activity, a
fragment, a notification
etc…
In this case it’s an
activity
Presentation Layer in practise
public class ExamplePresenter {

private ExampleScreen screen;



public ExamplePresenter(ExampleScreen screen) {

this.screen = screen;

}



public void initialize() {

getData();

}



void getData() {

screen.showLoading();

BusProvider.getUIBusInstance().register(this);

new GetDataUseCase(new WebDataRepository()).execute();

}



@Subscribe

public void onGetDataResponse(Data data) {
BusProvider.getUIBusInstance().unregister(this);

screen.hideLoading();

screen.showData(data);

}



@Subscribe

public void onGetDataError(Error error) {
BusProvider.getUIBusInstance().unregister(this);

screen.hideLoading();

screen.showError(error.getMessage());

}

}
public interface ExampleScreen { 

void showLoading();



void hideLoading();



void showData(Data data);



void showError(String error);

}
The presenter is
communicating solely
with the screen and
not with the Android
Component
Domain Layer
• This layer orchestrates the data flow
Presenter
Use Case
Model
DataSource
Interface
Main (UI) Bus Provider
Domain Layer
Rest Bus Provider
Domain Layer in practise
public interface GetDataSource {

void getData();

}
public class Data implements Serializable {

private String dataStr;



public String getDataStr() {

return dataStr;

}



public void setDataStr(String dataStr) {

this.dataStr = dataStr;

}

}
public class GetDataUseCase {

private GetDataSource dataSource;



public GetDataUseCase(GetDataSource dataSource) {

this.dataSource = dataSource;

}



@Subscribe

public void onGetDataResponse(Data data) {

BusProvider.getUIBus().post(data);


BusProvider.getRestBus().unregister(this);

}



@Subscribe

public void onGetDataError(Error error) {

BusProvider.getUIBus().post(error);



BusProvider.getRestBus().unregister(this);

}



public void execute() {

BusProvider.getRestBus().register(this);



dataSource.getData();

}

}
There is no reference
neither to the activity nor
to the “Retrofit code”
Data Layer
• This layer retrieves the data
DataSource
Interface
Domain Layer
Rest Bus Provider
WebDataRepository
DBDataRepository
CachedDataReposit
ory
Data
Mapper
Data layer
Data Layer in practise
public class WebDataRepository implements GetDataSource {

private DataClient client;



public WebDataRepository() {

client = Retrofit.createClient(DataClient.class);

}



@Override

public void getData() {

Call<DataEntity> call = client.getDataFromWeb();

call.enqueue(new Callback<DataEntity>() {

@Override

public void onResponse(Call<DataEntity> call,
Response<DataEntity> response) {
Data data = new DataMapper().transform(response.body());
BusProvider.getRestBusInstance().post(data);
}



@Override

public void onFailure(Call<DataEntity> call, Throwable t) {
Error error = new ErrorMapper().transform(t);

BusProvider.getRestBusInstance().post(error);

}

});
}
}

public class DataMapper {



public Data transform(
DataEntity entity) {

Data data = new Data();



data.setDataStr(
String.valueOf(entity.getInt()));



return data;

} 

}
Here is written the
implementation
detail
The mapper is a safe
mechanism to transform
the response to the data
we actually need
Why all the fuss?
• Our use cases need to implement the following mechanisms:
1. Reauthorisation
2. Caching
3. Server downtime handling
4. In App broadcasts
5. Redirect
6. Different geocoding services
• Presenters need to listen and show those In-Apps or handle redirect links
(Opening the appropriate activity)
Why all the fuss?
Feature Presenter
Base Presenter
Feature Use Case
Base Use Case
Repository
• Re-login
• Server Downtime
• In App Broadcasts
• Redirect
• Check reverse
geocoding results
• Show In App
Dialogs
• Handle redirect
navigation
Conclusion
• By following the rules of Clean Architecture we split the core
features’ code from the front end code.
• We can mock our rest responses and develop new features in
parallel with the server side development
• All the modules are testable.
• Newcomers can focus to the business side of the code and are
not lost on the plugin details, while learning the codebase.
• On the downside we have to write more code than we used to. To
combat that we created code templates inside Android Studio!
§
GitHub Project
https://github.com/bakoproductions/Pokemon-
Clean-Architecture-Example
The end!
Any questions?
We are hiring!
www.taxibeat.com/careers
Resources
• Uncle Bob

The original blog post: https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html

Talk: https://www.youtube.com/watch?v=Nsjsiz2A9mg
• Fernando Cejas

Sample app written with the clean architecture approach using Dagger and RxJava https://
github.com/android10/Android-CleanArchitecture
• Tomislav Homan

A series of articles that detail the process of migrating Five Agency’s apps to clean architecture
http://five.agency/android-architecture-part-1-every-new-beginning-is-hard/
• Chryssa Aliferi

Article series about the MVP @ Taxibeat https://medium.com/taxibeat/android-architecture-with-
multi-screen-mvp-46d3ccafa7b9

Presentation https://speakerdeck.com/chryssaaliferi/android-mvp-pattern-and-multi-presenter-
activities
§
Thank you!!
Michael Bakogiannis

Android Software Engineer

@bakoproductions

More Related Content

What's hot

Serious Sencha - Data Layer and Server-Side REST Interface
Serious Sencha - Data Layer and Server-Side REST InterfaceSerious Sencha - Data Layer and Server-Side REST Interface
Serious Sencha - Data Layer and Server-Side REST InterfaceKlaus Hofeditz
 
Converting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile CloudConverting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile CloudRoger Brinkley
 
How to Practice TDD Without Shooting Yourself in the Foot
How to Practice TDD Without Shooting Yourself in the FootHow to Practice TDD Without Shooting Yourself in the Foot
How to Practice TDD Without Shooting Yourself in the FootDennis Doomen
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every dayVadym Khondar
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorialMohammed Fazuluddin
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo Ali Parmaksiz
 

What's hot (7)

Serious Sencha - Data Layer and Server-Side REST Interface
Serious Sencha - Data Layer and Server-Side REST InterfaceSerious Sencha - Data Layer and Server-Side REST Interface
Serious Sencha - Data Layer and Server-Side REST Interface
 
Converting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile CloudConverting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile Cloud
 
How to Practice TDD Without Shooting Yourself in the Foot
How to Practice TDD Without Shooting Yourself in the FootHow to Practice TDD Without Shooting Yourself in the Foot
How to Practice TDD Without Shooting Yourself in the Foot
 
The Road To Redux
The Road To ReduxThe Road To Redux
The Road To Redux
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 

Similar to Clean Architecture @ Taxibeat

Cloud Native Serverless Java — Orkhan Gasimov
Cloud Native Serverless Java — Orkhan GasimovCloud Native Serverless Java — Orkhan Gasimov
Cloud Native Serverless Java — Orkhan GasimovGlobalLogic Ukraine
 
Front end microservices - October 2019
Front end microservices - October 2019Front end microservices - October 2019
Front end microservices - October 2019Mikhail Kuznetcov
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in reactBOSC Tech Labs
 
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On KubernetesHow To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On KubernetesLightbend
 
JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)Hendrik Ebbers
 
Functional Web Development
Functional Web DevelopmentFunctional Web Development
Functional Web DevelopmentFITC
 
Microservices with .Net - NDC Sydney, 2016
Microservices with .Net - NDC Sydney, 2016Microservices with .Net - NDC Sydney, 2016
Microservices with .Net - NDC Sydney, 2016Richard Banks
 
Building workflow solution with Microsoft Azure and Cloud | Integration Monday
Building workflow solution with Microsoft Azure and Cloud | Integration MondayBuilding workflow solution with Microsoft Azure and Cloud | Integration Monday
Building workflow solution with Microsoft Azure and Cloud | Integration MondayBizTalk360
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Eliran Eliassy
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDennis Doomen
 
2011 - DNC: REST Wars
2011 - DNC: REST Wars2011 - DNC: REST Wars
2011 - DNC: REST WarsDaniel Fisher
 
Developing Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationDeveloping Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationMark Gu
 
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...AWS Chicago
 
Spring Cloud Data Flow Overview
Spring Cloud Data Flow OverviewSpring Cloud Data Flow Overview
Spring Cloud Data Flow OverviewVMware Tanzu
 

Similar to Clean Architecture @ Taxibeat (20)

Cloud Native Serverless Java — Orkhan Gasimov
Cloud Native Serverless Java — Orkhan GasimovCloud Native Serverless Java — Orkhan Gasimov
Cloud Native Serverless Java — Orkhan Gasimov
 
Tdd,Ioc
Tdd,IocTdd,Ioc
Tdd,Ioc
 
Front end microservices - October 2019
Front end microservices - October 2019Front end microservices - October 2019
Front end microservices - October 2019
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
CQRS and Event Sourcing
CQRS and Event SourcingCQRS and Event Sourcing
CQRS and Event Sourcing
 
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On KubernetesHow To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
 
JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)
 
Functional Web Development
Functional Web DevelopmentFunctional Web Development
Functional Web Development
 
Android classes in mumbai
Android classes in mumbaiAndroid classes in mumbai
Android classes in mumbai
 
Microservices with .Net - NDC Sydney, 2016
Microservices with .Net - NDC Sydney, 2016Microservices with .Net - NDC Sydney, 2016
Microservices with .Net - NDC Sydney, 2016
 
Building workflow solution with Microsoft Azure and Cloud | Integration Monday
Building workflow solution with Microsoft Azure and Cloud | Integration MondayBuilding workflow solution with Microsoft Azure and Cloud | Integration Monday
Building workflow solution with Microsoft Azure and Cloud | Integration Monday
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservices
 
2011 - DNC: REST Wars
2011 - DNC: REST Wars2011 - DNC: REST Wars
2011 - DNC: REST Wars
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Developing Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationDeveloping Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web Application
 
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...
 
Mobile optimization
Mobile optimizationMobile optimization
Mobile optimization
 
Spring Cloud Data Flow Overview
Spring Cloud Data Flow OverviewSpring Cloud Data Flow Overview
Spring Cloud Data Flow Overview
 

Recently uploaded

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxnuruddin69
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 

Recently uploaded (20)

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 

Clean Architecture @ Taxibeat

  • 1. § How we are architecting Android at Taxibeat… the clean way. Michael Bakogiannis
 Android Software Engineer @bakoproductions
  • 2. Once upon a time…
  • 3. Once upon a time… • Driver and passenger apps started as two simple projects with the goal of providing an easy transportation platform for the people • There was a basic structure and some simple features • The need for expanding on different markets and tense competition forced quick changes to this structure making the code complex
  • 4. Complex meaning… • God Activities • Humongous helper/manager classes that became extra sophisticated • Legacy code • The code responsible for providing the UX (business rules) was tightly coupled with the code responsible for the UI
  • 5. App Redesign • A new architecture should be able to: • separate UI from UX • let as develop and debug faster • let as code on the same “activity” at the same time with the least of conflicts • provide a set of rules that new members of the team should follow so as to learn the codebase faster • be test friendly • A pattern like MVP was not enough
  • 7. Clean architecture to the rescue • It is not a pattern like MVP • It is a set of rules in order to create a layered approach. These layers are able to separate the platform specific code from the business rules I want you to think of your application as a group of use cases that describe the intent of the application and a group of plugins that give those use cases access to the outside world. 
 Robert C Martin “Uncle Bob”
  • 8. Dependency Rule Dependencies should only point inwards An inner circle should not know anything about an outer circle.
  • 9. Our Approach Presentation Layer MVP Pattern Domain Layer Business Models Data Layer Repository Pattern Interactors(UseCases) Datasources Read also here: https://github.com/android10/Android-CleanArchitecture
  • 10. Presentation Layer • This layer provides the UI and a great deal of the UX to the user Android Component Presenter Screen Interface • Android Components are the Activities, Services, Fragments, Notifications etc… • The Screen is an Interface that defines the methods that the Android Component should implement • The Presenter provides the business logic Read also here: https://medium.com/taxibeat/android-architecture-with-multi-screen- mvp-46d3ccafa7b9
  • 11. Presentation Layer in practise public class ExampleActivity extends AppCompatActivity implements ExampleScreen {
 private ExamplePresenter presenter;
 
 @Override
 protected void onCreate(@Nullable Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.act_example);
 presenter = new ExamplePresenter(this);
 presenter.initialize();
 }
 
 @Override
 public void showLoading() { /* Actual Implementation */ }
 
 @Override
 public void hideLoading() { /* Actual Implementation */ } 
 @Override
 public void showData(Data data) { /* Actual Implementation */ }
 
 @Override
 public void showError(String error) { /* Actual Implementation */ } 
 } public interface ExampleScreen {
 void showLoading();
 
 void hideLoading();
 
 void showData(Data data);
 
 void showError(String error);
 } The screen does not know who implements its methods It may be an activity, a fragment, a notification etc… In this case it’s an activity
  • 12. Presentation Layer in practise public class ExamplePresenter {
 private ExampleScreen screen;
 
 public ExamplePresenter(ExampleScreen screen) {
 this.screen = screen;
 }
 
 public void initialize() {
 getData();
 }
 
 void getData() {
 screen.showLoading();
 BusProvider.getUIBusInstance().register(this);
 new GetDataUseCase(new WebDataRepository()).execute();
 }
 
 @Subscribe
 public void onGetDataResponse(Data data) { BusProvider.getUIBusInstance().unregister(this);
 screen.hideLoading();
 screen.showData(data);
 }
 
 @Subscribe
 public void onGetDataError(Error error) { BusProvider.getUIBusInstance().unregister(this);
 screen.hideLoading();
 screen.showError(error.getMessage());
 }
 } public interface ExampleScreen { 
 void showLoading();
 
 void hideLoading();
 
 void showData(Data data);
 
 void showError(String error);
 } The presenter is communicating solely with the screen and not with the Android Component
  • 13. Domain Layer • This layer orchestrates the data flow Presenter Use Case Model DataSource Interface Main (UI) Bus Provider Domain Layer Rest Bus Provider
  • 14. Domain Layer in practise public interface GetDataSource {
 void getData();
 } public class Data implements Serializable {
 private String dataStr;
 
 public String getDataStr() {
 return dataStr;
 }
 
 public void setDataStr(String dataStr) {
 this.dataStr = dataStr;
 }
 } public class GetDataUseCase {
 private GetDataSource dataSource;
 
 public GetDataUseCase(GetDataSource dataSource) {
 this.dataSource = dataSource;
 }
 
 @Subscribe
 public void onGetDataResponse(Data data) {
 BusProvider.getUIBus().post(data); 
 BusProvider.getRestBus().unregister(this);
 }
 
 @Subscribe
 public void onGetDataError(Error error) {
 BusProvider.getUIBus().post(error);
 
 BusProvider.getRestBus().unregister(this);
 }
 
 public void execute() {
 BusProvider.getRestBus().register(this);
 
 dataSource.getData();
 }
 } There is no reference neither to the activity nor to the “Retrofit code”
  • 15. Data Layer • This layer retrieves the data DataSource Interface Domain Layer Rest Bus Provider WebDataRepository DBDataRepository CachedDataReposit ory Data Mapper Data layer
  • 16. Data Layer in practise public class WebDataRepository implements GetDataSource {
 private DataClient client;
 
 public WebDataRepository() {
 client = Retrofit.createClient(DataClient.class);
 }
 
 @Override
 public void getData() {
 Call<DataEntity> call = client.getDataFromWeb();
 call.enqueue(new Callback<DataEntity>() {
 @Override
 public void onResponse(Call<DataEntity> call, Response<DataEntity> response) { Data data = new DataMapper().transform(response.body()); BusProvider.getRestBusInstance().post(data); }
 
 @Override
 public void onFailure(Call<DataEntity> call, Throwable t) { Error error = new ErrorMapper().transform(t);
 BusProvider.getRestBusInstance().post(error);
 }
 }); } }
 public class DataMapper {
 
 public Data transform( DataEntity entity) {
 Data data = new Data();
 
 data.setDataStr( String.valueOf(entity.getInt()));
 
 return data;
 } 
 } Here is written the implementation detail The mapper is a safe mechanism to transform the response to the data we actually need
  • 17. Why all the fuss? • Our use cases need to implement the following mechanisms: 1. Reauthorisation 2. Caching 3. Server downtime handling 4. In App broadcasts 5. Redirect 6. Different geocoding services • Presenters need to listen and show those In-Apps or handle redirect links (Opening the appropriate activity)
  • 18. Why all the fuss? Feature Presenter Base Presenter Feature Use Case Base Use Case Repository • Re-login • Server Downtime • In App Broadcasts • Redirect • Check reverse geocoding results • Show In App Dialogs • Handle redirect navigation
  • 19. Conclusion • By following the rules of Clean Architecture we split the core features’ code from the front end code. • We can mock our rest responses and develop new features in parallel with the server side development • All the modules are testable. • Newcomers can focus to the business side of the code and are not lost on the plugin details, while learning the codebase. • On the downside we have to write more code than we used to. To combat that we created code templates inside Android Studio!
  • 23. Resources • Uncle Bob
 The original blog post: https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html
 Talk: https://www.youtube.com/watch?v=Nsjsiz2A9mg • Fernando Cejas
 Sample app written with the clean architecture approach using Dagger and RxJava https:// github.com/android10/Android-CleanArchitecture • Tomislav Homan
 A series of articles that detail the process of migrating Five Agency’s apps to clean architecture http://five.agency/android-architecture-part-1-every-new-beginning-is-hard/ • Chryssa Aliferi
 Article series about the MVP @ Taxibeat https://medium.com/taxibeat/android-architecture-with- multi-screen-mvp-46d3ccafa7b9
 Presentation https://speakerdeck.com/chryssaaliferi/android-mvp-pattern-and-multi-presenter- activities
  • 24. § Thank you!! Michael Bakogiannis
 Android Software Engineer @bakoproductions