SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
§
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Ähnlich wie Clean Architecture @ Taxibeat

Functional Web Development
Functional Web DevelopmentFunctional Web Development
Functional Web Development
FITC
 

Ähnlich wie 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
 

Kürzlich hochgeladen

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 

Kürzlich hochgeladen (20)

Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 

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