Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clean Architecture in Android

Clean Architecture in Android

This talk is for clean architecture and how to apply it in android development for members at PrimeLabo

Avatar for Thanh Chinh Ban

Thanh Chinh Ban

August 19, 2016
Tweet

More Decks by Thanh Chinh Ban

Other Decks in Programming

Transcript

  1. Ban Chính Thành • A Little ninja at PrimeLabo •

    Android developer Email:[email protected] Github: http://github.com/thanhbc
  2. Generally in Clean, code is separated into layers in an

    onion shape with one dependency rule: The inner layers should not know anything about the outer layers. Meaning that the dependencies should point inwards.
  3. It makes your code • Independent of Frameworks • Testable

    • Independent of UI • Independent of Database • Independent of any external agency
  4. Some vocabulary • Entities: These are the business objects of

    the application. • Use cases: These use cases orchestrate the flow of data to and from the entities. Are also called Interactors. • Interface Adapters: This set of adapters convert data from the format most convenient for the use cases and entities. Presenters and Controllers belong here. • Frameworks and Drivers: This is where all the details go: UI, tools, frameworks, etc.
  5. The Objective is the separation of concerns by keeping the

    business rules not knowing anything at all about the outside world!
  6. Presentation Layer • Where the logic related with views and

    animations happens • There is no logic inside them other than UI logic • Presenters in this layer are composed with interactors (use cases) that perform the job in a new thread outside the android UI thread, and come back using a callback with the data that will be rendered in the view
  7. Domain Layer • Business rules here: all logic happens in

    this layer. • All the external components use interfaces when connecting to the business objects.
  8. Data Layer All data needed for the application comes from

    this layer through a UserRepository implementation (the interface is in the domain layer) that uses a Repository Pattern with a strategy that, through a factory, picks different data sources depending on certain conditions.