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 full-size 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 full-size slide

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

    View full-size slide

  4. 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 full-size 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.
    • Growth: a module should not increase size without bounds.

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. :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 full-size slide

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

    View full-size slide

  11. 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 full-size slide

  12. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  15. 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 full-size slide

  16. What is a feature?

    View full-size slide

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

    View full-size slide

  18. :app
    :feature1

    View full-size slide

  19. :app
    :feature1 :feature2

    View full-size slide

  20. :app
    :feature1 :feature2 :feature3

    View full-size slide

  21. :app
    :feature1 :feature2 :feature3 :feature4

    View full-size slide

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

    View full-size slide

  23. 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 full-size slide

  24. 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 full-size slide

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

    View full-size slide

  26. Micro-Module Architecture

    View full-size slide

  27. :app
    :feature1

    View full-size slide

  28. :app
    :feature2
    :feature1

    View full-size slide

  29. :app
    :feature2
    :feature1
    :component1

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  33. Module Structure

    View full-size slide

  34. :module
    ui
    activity
    fragment
    viewmodel

    View full-size slide

  35. :module
    domain
    ui
    activity
    fragment
    viewmodel

    View full-size slide

  36. :module
    domain
    ui
    model
    usecase

    repository
    activity
    fragment
    viewmodel

    View full-size slide

  37. :module
    domain
    data
    ui
    model
    usecase

    repository
    activity
    fragment
    viewmodel

    View full-size slide

  38. :module
    domain
    data
    ui
    model
    usecase

    repository
    activity
    fragment
    viewmodel repository

    View full-size slide

  39. :module
    domain
    data
    ui
    model
    usecase

    repository
    activity
    fragment
    viewmodel
    store
    repository
    local
    remote

    View full-size slide