Domain Layer

Domain layer is located between the UI layer and the data layer. The UI layer interacts with the domain layer through use cases.

The domain layer in Android Clean Architecture is responsible for encapsulating the core business logic of the application. It defines the rules and operations that are specific to the problem domain of the application, independent of any UI or data access concerns.

In Clean Architecture, the domain layer is located between the UI layer and the data layer. The UI layer interacts with the domain layer through use cases. The data layer interacts with the domain layer through repositories. This separation of concerns makes the code more modular and easier to maintain.

UseCase

In Android Clean Architecture, a use case is a central component that encapsulates a specific piece of business logic or a specific task that your application performs. Use cases help achieve the separation of concerns by decoupling the business logic from the user interface and data layers. They are typically part of the domain layer in the Clean Architecture. For example:

interface MovieUseCase {
    suspend fun getDetailMovie(id: Int): Flow<Resource<MovieDetail>>
}

Interactor

In Android Clean Architecture, an interactor is another term for a use case. Interactors are responsible for executing specific pieces of business logic or tasks within the application. And in onelib, the interactor becomes the place for mapping data. For example:

class MovieInteractor(private val repository: MovieRepository) : MovieUseCase {

    override suspend fun getDetailMovie(id: Int): Flow<Resource<MovieDetail>> {
        return repository.getDetailMovie(id).map { resource ->
            resource.oneMap { response -> response.toDomain() }
        }
    }

}

oneMap is a extension function for mapping object.

Model

In Android development, the term "model" refers to a component that represents the data and business logic of an application. The model is responsible for managing the data, whether it's fetched from a remote server, stored in a local database, or kept in memory. The model is part of the MVVM (Model-View-ViewModel) architectural patterns commonly used in Android development.

data class MovieDetail(
    @SerializedName("id")
    val id: Int? = 0,
    @SerializedName("backdrop_path")
    val backdropPath: String? = "",
    @SerializedName("overview")
    val overview: String? = "",
    @SerializedName("poster_path")
    val posterPath: String? = "",
    @SerializedName("release_date")
    val releaseDate: String? = "",
    @SerializedName("runtime")
    val runtime: Int? = 0,
    @SerializedName("title")
    val title: String? = "",
)

Model Mapping

In Android development, a model mapper is a component or utility that helps convert one model type to another. This is particularly useful when you need to transform data from one layer of your application to another, such as converting data transfer objects (DTOs) from a network response into domain models used within the app, or vice versa.

fun MovieDetailResultResponse.toDomain(): MovieDetail =
    MovieDetail(
        id = id,
        posterPath = posterPath,
        backdropPath = backdropPath,
        overview = overview,
        title = title,
        releaseDate = releaseDate
    )

Last updated