Save 37% off PRO during our Black Friday Sale! »

Android Modular Architecture

Android Modular Architecture

Building a quality software is a complex task. This isn't just a matter of satisfying the business requirements. The software needs to be robust, easy-to-maintain, testable, and flexible to adapt to the various changes that an agile team needs to face.

In this presentation, I will walk you through planning and refactoring of a modern Android application built for a large-scale user base.

5cefbec62d834db21a3823a8e66d59d8?s=128

Marcello Galhardo
PRO

November 11, 2018
Tweet

Transcript

  1. Android Modular Architecture

  2. Christopher Alexander “It is the first steps in a design

    process which count for most. The first few strokes, creates the form.”
  3. Challenges

  4. Challenges • Independence: be able to work in a feature

    without impacting other developers.
  5. Challenges • Independence: be able to work in a feature

    without impacting other developers. • Encapsulation: effective use of access modifiers to hide information from different modules.
  6. Challenges • Independence: be able to work in a feature

    without impacting other developers. • Encapsulation: effective use of access modifiers to hide information from different modules. • Growth: a module should not increase size without bounds.
  7. Module by Layer In Module by Layer, the highest level

    modules reflect the various application "layers", instead of features.
  8. :app

  9. :app :ui

  10. :app :domain :ui DI injects use case in the presentation.

  11. :app :domain :ui :data DI injects repository implementation in the

    domain. DI injects use case in the presentation.
  12. :app :domain :ui :data DI injects repository implementation in the

    domain. DI injects use case in the presentation. :app knows about all modules, and need to set up the DI.
  13. Challenges

  14. Challenges • Independence: features has its implementation spread out over

    multiple modules.
  15. Challenges • Independence: features has its implementation spread out over

    multiple modules. • Encapsulation: modules contains items that usually aren't closely related to each other.
  16. Challenges • Independence: features has its implementation spread out over

    multiple modules. • Encapsulation: modules contains items that usually aren't closely related to each other. • Growth: As an application grows, the number of modules remains the same, while the number of classes in each module will increase without bound.
  17. This results in modules with low cohesion with high coupling

    between each other.
  18. The fundamental flaw with Module by Layer is that it

    puts implementation details ahead of high level abstractions.
  19. Module by Feature Module by Feature uses modules to reflect

    the feature set. It tries to place all items related to a single feature (and only that feature) into a single module.
  20. What is a feature?

  21. What is a feature? A feature is fully independent, fine-grained

    and self contained service those messages are delivered over Intent by URLs.
  22. :app

  23. :app :feature1

  24. :app :feature1 :feature2

  25. :app :feature1 :feature2 :feature3

  26. :app :feature1 :feature2 :feature3 :feature4

  27. Challenges

  28. Challenges • Independence: all items needed for a given feature

    are in the same module.
  29. Challenges • Independence: all items needed for a given feature

    are in the same module. • Encapsulation: allows classes to decrease their scope from public to internal.
  30. Challenges • Independence: all items needed for a given feature

    are in the same module. • Encapsulation: allows classes to decrease their scope from public to internal. • Growth: the number of classes within each package remains limited to the items related to a specific feature.
  31. This results in modules with high cohesion and low coupling

    between each other.
  32. Micro-Module Architecture

  33. :app

  34. :app :feature1

  35. :app :feature2 :feature1

  36. :app :feature2 :feature1 :component1

  37. :app :feature2 :common :feature1 :component1 :design :testing

  38. :app :feature2 :common :feature3 :feature1 :component1 :design :testing

  39. :app :feature2 :component2 :common :feature3 :feature1 :component1 :design :testing

  40. Module Structure

  41. :module

  42. :module ui

  43. :module ui activity fragment viewmodel

  44. :module domain ui activity fragment viewmodel

  45. :module domain ui model usecase <interface>
 repository activity fragment viewmodel

  46. :module domain data ui model usecase <interface>
 repository activity fragment

    viewmodel
  47. :module domain data ui model usecase <interface>
 repository activity fragment

    viewmodel repository
  48. :module domain data ui model usecase <interface>
 repository activity fragment

    viewmodel store repository local remote
  49. Thank you.