• The CLEAN Architecture was created by Robert C. Martin (“Uncle Bob”) to make code more maintainable and easier to manage if modifying for different services.
  • Separation of UI, Entity, Models, and Services
  • alt-text-here

    alt-text-here

    - Isolation of Responsibilities

    - Decoupled Structure

    - Single Purpose Entities

    alt-text-here

    The Clean Architecture is built upon the "SOLID" principles which are:

    alt-text-here
  • Feature Directory   (Separation of layers)

  • Example Directory Structure ↓
  • alt-text-here
    alt-text-here

    Service Models

  • The Request Model is created and provided to the Service Adapter
  • The Response Model is created and provided to the Service Adapter
  • The Service Adapter maps the JSON response to the Response Model Entity
  • BLoc

    Service Adapter

  • Provides the following to the specific service
  • Provides method for mapping the response to the Entity Model
  • Use Case

  • Utilizes a Repository Scope
  • Provides Constructor for Specific Use Case Types
  • Provides linkage to parent Repository Scope
  • Define linkage to children Entity Scope Types
  • Enables construction of View Model
  • Entity

  • The object types created for the particular use case(s)
  • Also known as the Domain Model
  • View Model

  • View Model will be the middle man between the UI and the Use Case
  • The object mapping to the UI to be displayed
  • A View Model List may also be provided instead of a View Model if multiple JSON objects are returned
  • Feature Widget

  • Creates BLoc
  • Associates a Presenter to the BLoc
  • Presenter

  • Creates the "Screen" based off of:
  • Screen

  • The actual UI Widget being present for the specific Use Case
  • This is where the View Model (or View Model List) will map the data to the UI
  • alt-text-here

    alt-text-here

    alt-text-here

    alt-text-here

  • Use Case: Retreive Cash Accounts
  • alt-text-here

  • Abstraction of Data/Dependency Layer
  • Maps Scope to Entities
  • Manages Scopes
  • Executes Service Adapter Functionality
  • Essentially, provides a "container" for any specific Entity to operate within the CLEAN architecture
  • Maps Scope to Entities

    Repository contains Entities with data and Scope mapped to that Entity:

            /// Creates a Map collection of Repository Scope and Entity Type.
            Map<RepositoryScope, Entity> scopes = {};

    To get a Scope for current Entity use method:

            /// Checks if a Scope is associated with a specific Entity Type.
            containsScope<E extends Entity>()

    To get an Entity for current scope use method:

            /// Returns the Entity associated with the Scope in the Map collection.
            get<E extends Entity>(RepositoryScope scope)

    Manages Scopes

    To create a new scope for an existing Entity use method:

            /// Creates a Scope if One is not already set, if set return existing scope. 
            create<E extends Entity>(E entity, Function(dynamic) subscription)

    To update a scope for an existing Entity use method:

            /// Updates an existing Scope to a scope provided to the method.
            update<E extends Entity>(RepositoryScope scope, E entity)

    Executes Service Adapter

    To execute the Service Adapter use method:

            /// Execute the provided Service Adapter with the associated Scope.
            runServiceAdapter(RepositoryScope scope, ServiceAdapter adapter)

    alt-text-here

  • Contains the primary logic for the functionality of the feature being implemented
  • Contains implementation of all the methods that should be executed in response to events
  • Contains View Model Callback which communicates with View Model Pipe in the BLoc

  • What should be contained in a Use Case?

  • A Repository associating a Scope with an Entity
  • If a service is needed, the Use Case associates the Service Adapter to the Repository Scope
  • If updating UI, building of a View Model and providing the View Model via a callback function through the Repository
  • alt-text-here

    alt-text-here

    alt-text-here

    alt-text-here

    alt-text-here

    alt-text-here

    AndroidPub - Milhay Nagy

    Uncle Bob - Clean Coder

    geeksforgeeks - SOLID Principles