Domain Layer

The Domain Layer defines the business objects, specifications and use cases of the application.

The Domain layer is independent of the other layers of the application and is not concerned with the details of how the application is implemented or how it is presented to the user. It defines the business objects and the rules that govern them, as well as the specifications and use cases that describe the various actions and interactions that can be performed within the application.

Entity

An Entity is a business object that represents the core data structures and objects which are used throughout the application.

External Data Models must be mapped into Entities to decouple the Presentation Layer from the details of the external dependencies of the Infrastructure Layer. This ensures that the Presentation Layer only has to work with a consistent set of data structures and objects, rather than handling a variety of Data Models from different and ever-changing Data Sources. This separation between the Presentation and Infrastructure layers makes it easier to manage and maintain the system, for example when migrating to a new database with a different Data Model.

Examples of entities are: UserInfo, Address, Note.

Failure

A Failure is a business object which signifies an error in the application.

It is the responsibility of the Presentation Layer to handle these Failure objects, and any exceptions that occur in the Infrastructure Layer should be converted into the corresponding Failure object. This helps to decouple the Presentation Layer from the Infrastructure layer, as the Failure objects received by the Presentation Layer will remain consistent, even if changes are made to the Infrastructure Layer which allows for more flexibility and maintainability in the application.

Examples of failures are: NetworkFailure, InvalidEmailFailure, InvalidPasswordFailure.

An error should not be converted into Failure.

Exceptions are generated when something fails caused by an external dependency or by the user. On the other hand, errors signify a developer mistake in the code. Hence, this should be handled by the developer and should never reach production.

Repository (Interface)

A Repository Interface is a class that defines the functions and capabilities of a specific data repository.

It is an interface class, which means that it does not contain any implementation details. Instead, it is simply a set of declarations that define the methods and functions that should be provided by the repository. It is the responsibility of the Infrastructure Layer to provide the actual implementation of these methods and functions using the appropriate technologies and tools.

Examples of repositories are: AuthenticationRepository, SubscriptionRepository, UserRepository.

Use Case

A Use Case defines a specific action that can be triggered by the client application.

It is a specialized class called from the Presentation Layer to request infrastructure-level data or simply perform a particular work in the Infrastructure Layer. The Use Case accomplishes this task by using one or more Repositories to communicate with the application's infrastructure.

A successful Use Case execution returns a primitive object or an Entity. On the other hand, if an error occurs then a Failure will be returned instead.

Examples of use cases are: SetName, FetchName, WatchUserInfo (Data stream).

Last updated