Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Layer_Definition en

Tetsuya Mori edited this page Sep 11, 2018 · 6 revisions

Layer definition

CAFU defines the following layers based on the rules of Clean Architecture.

  • Domain
    • Entity
    • Structure
    • UseCase
    • Translator
  • Presentation
    • Presenter
    • View
  • Data
    • Repository
    • DataStore
  • Other
    • Resolver

The class diagram is as below.

class diagram

The relations of Entity, Structure and Translator as below.

entity, structure and translator

Domain > Entity

This layer to have the core data structure and behaviors for a single responsibility of the application.

This layer will be defined the state and behavior on the premise that the class is divided by actor and responsibility unit.

As a general rule, instances of the Entity layer do not move between other layers, they are required to be referred to only from UseCase.

Responsibilities

  • Define and implement states and behaviors restricted to actors and responsibilities
  • Provide properties for holding the result of UseCase processing

Associations

Nothing.

Domain > Structure

This layer to have manage structured data for outside the application (Data Structure) or handling data acting on drawing (Presentation Structure).

Stored in this layer is data provided by any external data such as Local Storage, Web API, Object Storage and mBaaS database.
The Structure layer is not a direct interface with external services that hold external data.
It merely expresses the structure of external data, and the DataStore layer described later handles dialogue with the external system.

It also stores the information necessary for drawing in this layer with the appropriate granularity.
In addition, we received a structure that has a Stream (ReactiveProperty, etc.) notifying the change of the value as a pro party, received through the presenter, and made sparse bonds can be received on the side of seeing the update by UseCase.

In addition, it is strongly required to separately define data that acts on drawing and outside the game according to the principle of single responsibility.
Of course, it is possible to exchange data using the same data, but since it is necessary to modify the logic related to the drawing specifications when the external specification changes, for example, it is divided so that change contamination can be stopped at the Translator layer It can be said that it is desirable to define it.

Responsibilities

  • Structure and manage the data handled by the external system
  • Provide IObservable for monitoring changes in View
    • ReactiveProperty is useful

Associations

Nothing.

Domain > UseCase

It is a layer for describing business logic.

Calculate processing according to the requirements of the application for events from View sent via Presenter and manipulate Entities held as state.
Also, it converts Structure received from Repository through Translator, and it also has the role of passing data to Presenter.
In addition, it plays a role of sending data to be saved in the external system through the Repository.
It is a place to implement as the foundation of the product and it is vital to narrow down appropriately the responsibilities given to the class itself according to the principle of single responsibility.

It should be noted that when transferring Structure between Presentation layer and Data layer, you should not neglect the conversion process through Translator.

Responsibilities

  • Perform necessary calculations based on events sent from Presenter      * Example: Initialize the time management entity with the initial value of 30 seconds for the call to start the countdown timer of 30 seconds and subtract the difference seconds per frame
  • Return Stream, Entity, etc. to notify and notify Structure etc for use in View layer by initialization processing etc.      * Example: Return an instance of Structure with ReactiveProperty to notify the number of seconds of the countdown timer
  • When processing data to an external system, give an instruction to the appropriate Repository

Associations

  • Entity     * Reflect processing result for use in View
  • Translator     * Example: Pass the Data Structure obtained from the Repository to the Translator for Presentation Structure transformation and pass the return value to the Repository     * Example: Pass Presentation Structure obtained from Presenter to Translator for Entity conversion as state and hold the return value as instance     * Example: Extract Structure for Presentation layer from Entity and pass it to Presenter
  • Presentation interface defined for UseCase layer     * Call the processing of the abstraction that Presenter depends on     * Example: Subscribe to Observable for touch event notification     * Example: Pass Entity converted for Presentation layer to draw
  • For the Repository defined for UseCase layer interface     * Call the processing of the abstract that the Repository should depend on     * Example: Subscribe to Observable for notification of completion of reading external data     * Example: Pass the Structure converted for the Data layer to make it persistent to storage

Domain > Translator

This layer is for converting Entity and Structure to each other.
In response to the instruction from UseCase, construct the required instance.
It is a layer installed so as not to accompany modification to the UseCase layer against changes of external data and drawing composition.

Responsibilities

  • Extract Presentation Structure from Entity
  • Extract data structure from entity
  • Configure entities from the presentation structure
  • Configure entities from data structures
  • Convert presentation structure to data structure
  • Convert from data structure to presentation structure

Associations

  • Entity      * Construct Entity based on 0 or more Structure and primitive value
  • Presentation Structure      * Construct a Presentation Structure based on zero or more Entities, Structure and primitive values
  • Data Structure      * Construct Data Structure based on zero or more Entities, Structure or primitive values

Presentation > Presenter

This layer is for connecting View and UseCase.
We will bridge the fact that it will return the Observable of the View that should be used upon receiving a command from UseCase.
In addition, we will also receive a Presentation Structure etc. from UseCase and pass it to View.

Responsibilities

  • Pass Observable to notify any event execution to UseCase      * Example: Publish a method to notify the close button tap method call
  • Pass data passed from UseCase to View      * Example: Elapsed time management Passes elapsed time provided by UseCase to View

Associations

  • Presentation interface defined for UseCase layer      * Reveal methods necessary for processing instructions required by UseCase
  • Interface for View defined in the Presenter layer      * Bridge data passed from UseCase to View

Presentation > View

This layer is for processing which directly interacts with the user such as visual control and input event processing.
As the main responsibility, when an event occurs, notify Presenter of it or draw a Presentation Structure etc. according to the drawing instruction notified from Presenter.
Ideally, you should not know about other views than child elements.

Responsibilities

  • Drawing elements to be displayed on the screen etc.      * Example: Draw a Sprite corresponding to the current number of seconds passed on the screen when the time advances by 1 second
  • Processing input from users      * Example: Publish a method notifying that a tap event has occurred for the close button
  • Generation and destruction of structurally close elements      * Example: Instantiate items that become child elements of the list at initialization

Associations

  • Interface for View defined in the Presenter layer      * Publish methods required for processing instructions required by Presenter
  • Presentation Structure      * Passed from Presenter as a set of data related to drawing

Domain > Repository

This layer is for connecting UseCase and DataStore.
There may be just an interface-like Repository that only interacts with a single DataStore, and there may be Repositories that interact with multiple DataStores depending on the situation.

Responsibilities

  • Acquire Data Structure from DataStore      * It does not know what kind of means DataStore is acquiring
  • Store Data Structure in DataStore      * Does not know what kind of means DataStore stores

Associations

  • For the Repository defined for UseCase layer interface      * Reveal methods necessary for processing instructions required by UseCase
  • Interface for DataStore defined in the Repository layer      * Handle multiple DataStore while switching according to conditions      * Example: Query the local storage DataStore and use it if there is a cache and retrieve it from WebAPI DataStore if it is not cached

Data > DataStore

It is a layer that obtains data from an external system, acquires data necessary for constructing an instance of Data Structure, and saves and persists the data provided by Data Structure in an external system.
I know how to talk to the external system and it is the only layer that connects the world in the product and the outside world.

Responsibilities

  • Interact with an external system to obtain the data necessary for constructing an instance of Data Structure or to persist data derived from an instance of Data Structure      * Example: Deserialize JSON format string obtained from server to primitive type data and pass it to Repository      * Example: Serialize the primitive type data passed from the Repository into JSON format string and store it in local storage

Associations

  • Interface for DataStore defined in the Repository layer      * Example: De-serialize data obtained from WebAPI using JsonUtility.FromJson method      * Example: Serialize primitive type data using JsonUtility.ToJson method
  • Data Structure      * It is passed from Repository as a group of data to be processed