Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
Clean architecture: Android
Michał Szczepanik
WroDroid
3
4
5
6
I have a Dream...
7
What a Terrible Failure!
8
What is Architecture?
9
Architecture is About Intent, not Frameworks
„
10
Our goal(s)
● Architecture focused on use cases and main
system function
● Clear use cases first!
● Easy to maintain
● ...
11
Step 0 (setup?)
12
Architect role
13
Team Role
14
Android best practices ?
15
16
Entities
The business objects of the application
17
Use Cases
Use Cases orchestrate the flow of data to and
from the entities.
They are also called Interactors.
18
Interface Adapters
This set of adapters convert data from the format
most convenient for the use cases and entities.
Pr...
19
Frameworks and Drivers
This is where all the details go: UI, tools,
frameworks, etc.
20
21
How to be clean ?
22
23
App architecture – android view
24
App architecture – developer view
Presentation
Layer
Domain/Business
Layer
Data
Layer
Entities Layer
Interactors
Bounda...
25
Domain (Business) Layer
● Application business rules
● All use cases (interactors)
● Android independent
26
Domain (Business) Layer
Domain/Business
Layer
Entities Layer
InteractorsInterfaces
Repository(Dataaccess)Interface
● In...
27
Entities Layer
● Basic (minimal) business object
● Object's structure
● Low-level rules
● General truths
● Android inde...
28
Entities Layer
● Basic java object
● No frameworks
● Test for business objects
● No mocks and stubs
Domain/Business
Lay...
29
Presentation Layer
● Logic related to UI (view and animation)
● Logic related to Activity and application lifecycle
● F...
30
Presentation Layer
● Frameworks
● Integration (platform) tests
● UI tests
● (Android Instrumentation)
● (Robotium/Espre...
31
Data Layer
● Deliver data needed by app
● Cache
● Service
● Design: with Repository Pattern
32
Data Layer
● Repository Pattern
● Integration tests
● Unit tests
● (JUnit plus mockito)
● (Robolectric)
Implementation
...
33
34
Testing
● Low-level tests are fast
● High-level tests are slow
● UI testing sucks ?
● Self testing code ?
● new bug = n...
35
QA Team
36
Monkey
adb shell monkey [options] <event-count>
-s <seed>
-v <verbosity level>
37
Android Tips
38
65K
Unable to execute dex: method ID not in [0, 0xffff]: 65536
Conversion to Dalvik format failed: Unable to execute de...
39
How to solve it
● Find reason
– dex-method-counts
● jarjar
● Shrinking libs via Proguard
● Multidex
40
41
Dalvik / ART
● Dalvik:
– Register-based machine
– Just in time (JIT): 2.3+
● ART
– Ahead-of-time (AOT)
42
Tools?
43
Lint
● Static Code Analysis
● Layouts tips and optimization
● Missing translations
● Layout performance problems
● Unus...
44
Dependency Injections
● Dagger
● RoboGuice
45
Injections
● ButterKnife
● AndroidAnnotations
46
Injections
class ExampleActivity extends Activity {
@InjectView(R.id.title) TextView title;
@InjectView(R.id.subtitle) ...
47
Proguard / Dexguard
● Shrinking
● Optimize
● Obfuscate
48
Developer options
49
Clean Architecture
● Easy to maintain
● Easy to test
● Very cohesive
● Decoupled
50
WroDroid
http://www.meetup.com/WroDroid/
Clean Architecture by Unkle Bob
http://goo.gl/Z4zMHG
Architecting Android…The ...
51
Thank you for your attention
52
Questions ?
michal.szczepanik@blstream.com
Próxima SlideShare
Cargando en…5
×

Clean architecture: Android

6.854 visualizaciones

Publicado el

Publicado en: Tecnología
  • Sé el primero en comentar

Clean architecture: Android

  1. 1. Clean architecture: Android Michał Szczepanik
  2. 2. WroDroid
  3. 3. 3
  4. 4. 4
  5. 5. 5
  6. 6. 6 I have a Dream...
  7. 7. 7 What a Terrible Failure!
  8. 8. 8 What is Architecture?
  9. 9. 9 Architecture is About Intent, not Frameworks „
  10. 10. 10 Our goal(s) ● Architecture focused on use cases and main system function ● Clear use cases first! ● Easy to maintain ● Fast to test ● Easy to test ● Very cohesive ● Decoupled
  11. 11. 11 Step 0 (setup?)
  12. 12. 12 Architect role
  13. 13. 13 Team Role
  14. 14. 14 Android best practices ?
  15. 15. 15
  16. 16. 16 Entities The business objects of the application
  17. 17. 17 Use Cases Use Cases orchestrate the flow of data to and from the entities. They are also called Interactors.
  18. 18. 18 Interface Adapters This set of adapters convert data from the format most convenient for the use cases and entities. Presenters and Controllers belong here.
  19. 19. 19 Frameworks and Drivers This is where all the details go: UI, tools, frameworks, etc.
  20. 20. 20
  21. 21. 21 How to be clean ?
  22. 22. 22
  23. 23. 23 App architecture – android view
  24. 24. 24 App architecture – developer view Presentation Layer Domain/Business Layer Data Layer Entities Layer Interactors Boundaries
  25. 25. 25 Domain (Business) Layer ● Application business rules ● All use cases (interactors) ● Android independent
  26. 26. 26 Domain (Business) Layer Domain/Business Layer Entities Layer InteractorsInterfaces Repository(Dataaccess)Interface ● Interactors Implementation ● Use entities objects ● Most tests are here ● (JUnit plus mockito)
  27. 27. 27 Entities Layer ● Basic (minimal) business object ● Object's structure ● Low-level rules ● General truths ● Android independent ● Framework independent
  28. 28. 28 Entities Layer ● Basic java object ● No frameworks ● Test for business objects ● No mocks and stubs Domain/Business Layer Entities Layer Interactors Boundaries
  29. 29. 29 Presentation Layer ● Logic related to UI (view and animation) ● Logic related to Activity and application lifecycle ● Fragments and Activities are only views! ● Design: MVP/MVC/MVVM pattern ● Strongly connected with Android SDK
  30. 30. 30 Presentation Layer ● Frameworks ● Integration (platform) tests ● UI tests ● (Android Instrumentation) ● (Robotium/Espresso) ● (Robolectric) Presentation Layer Interactors
  31. 31. 31 Data Layer ● Deliver data needed by app ● Cache ● Service ● Design: with Repository Pattern
  32. 32. 32 Data Layer ● Repository Pattern ● Integration tests ● Unit tests ● (JUnit plus mockito) ● (Robolectric) Implementation RepositoryInterface Memory (cache) Disk (DB/File) Cloud
  33. 33. 33
  34. 34. 34 Testing ● Low-level tests are fast ● High-level tests are slow ● UI testing sucks ? ● Self testing code ? ● new bug = new test
  35. 35. 35 QA Team
  36. 36. 36 Monkey adb shell monkey [options] <event-count> -s <seed> -v <verbosity level>
  37. 37. 37 Android Tips
  38. 38. 38 65K Unable to execute dex: method ID not in [0, 0xffff]: 65536 Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536
  39. 39. 39 How to solve it ● Find reason – dex-method-counts ● jarjar ● Shrinking libs via Proguard ● Multidex
  40. 40. 40
  41. 41. 41 Dalvik / ART ● Dalvik: – Register-based machine – Just in time (JIT): 2.3+ ● ART – Ahead-of-time (AOT)
  42. 42. 42 Tools?
  43. 43. 43 Lint ● Static Code Analysis ● Layouts tips and optimization ● Missing translations ● Layout performance problems ● Unused resources ● Inconsistent array sizes ● Accessibility and internationalization problems ● Icon problems ● Usability problems ● Manifest errors
  44. 44. 44 Dependency Injections ● Dagger ● RoboGuice
  45. 45. 45 Injections ● ButterKnife ● AndroidAnnotations
  46. 46. 46 Injections class ExampleActivity extends Activity { @InjectView(R.id.title) TextView title; @InjectView(R.id.subtitle) TextView subtitle; @InjectView(R.id.footer) TextView footer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); ButterKnife.inject(this); // TODO Use "injected" views... } }
  47. 47. 47 Proguard / Dexguard ● Shrinking ● Optimize ● Obfuscate
  48. 48. 48 Developer options
  49. 49. 49 Clean Architecture ● Easy to maintain ● Easy to test ● Very cohesive ● Decoupled
  50. 50. 50 WroDroid http://www.meetup.com/WroDroid/ Clean Architecture by Unkle Bob http://goo.gl/Z4zMHG Architecting Android…The clean way http://goo.gl/MF13E1 Effective Android UI http://goo.gl/1dZxfb
  51. 51. 51 Thank you for your attention
  52. 52. 52 Questions ? michal.szczepanik@blstream.com

×