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

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.

Marcello Galhardo

November 11, 2018
Tweet

More Decks by Marcello Galhardo

Other Decks in Programming

Transcript

  1. Android
    Modular Architecture

    View Slide

  2. Christopher Alexander
    “It is the first steps in a design
    process which count for most. The
    first few strokes, creates the form.”

    View Slide

  3. Challenges

    View Slide

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

    View Slide

  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.

    View Slide

  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.

    View Slide

  7. Module by Layer
    In Module by Layer, the highest level modules
    reflect the various application "layers", instead of
    features.

    View Slide

  8. :app

    View Slide

  9. :app
    :ui

    View Slide

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

    View Slide

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

    View Slide

  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.

    View Slide

  13. Challenges

    View Slide

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

    View Slide

  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.

    View Slide

  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.

    View Slide

  17. This results in modules with low
    cohesion with high coupling
    between each other.

    View Slide

  18. The fundamental flaw with Module by
    Layer is that it puts implementation
    details ahead of high level abstractions.

    View Slide

  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.

    View Slide

  20. What is a feature?

    View Slide

  21. What is a feature?
    A feature is fully independent, fine-grained and self
    contained service those messages are delivered
    over Intent by URLs.

    View Slide

  22. :app

    View Slide

  23. :app
    :feature1

    View Slide

  24. :app
    :feature1 :feature2

    View Slide

  25. :app
    :feature1 :feature2 :feature3

    View Slide

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

    View Slide

  27. Challenges

    View Slide

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

    View Slide

  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.

    View Slide

  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.

    View Slide

  31. This results in modules with high
    cohesion and low coupling
    between each other.

    View Slide

  32. Micro-Module Architecture

    View Slide

  33. :app

    View Slide

  34. :app
    :feature1

    View Slide

  35. :app
    :feature2
    :feature1

    View Slide

  36. :app
    :feature2
    :feature1
    :component1

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  40. Module Structure

    View Slide

  41. :module

    View Slide

  42. :module
    ui

    View Slide

  43. :module
    ui
    activity
    fragment
    viewmodel

    View Slide

  44. :module
    domain
    ui
    activity
    fragment
    viewmodel

    View Slide

  45. :module
    domain
    ui
    model
    usecase

    repository
    activity
    fragment
    viewmodel

    View Slide

  46. :module
    domain
    data
    ui
    model
    usecase

    repository
    activity
    fragment
    viewmodel

    View Slide

  47. :module
    domain
    data
    ui
    model
    usecase

    repository
    activity
    fragment
    viewmodel repository

    View Slide

  48. :module
    domain
    data
    ui
    model
    usecase

    repository
    activity
    fragment
    viewmodel
    store
    repository
    local
    remote

    View Slide

  49. Thank you.

    View Slide