I'm learning Clean Architecture with the artical.
I know Domain Layer is the most INNER part of the onion (no dependencies with other layers) and it contains Entities, Use cases & Repository Interfaces.
I think I should use abstract class or interface in Use Case in Domain Layout, you can see Image 1 in the artical above.
The following code is from the project https://github.com/igorwojda/android-showcase
The internal class GetAlbumListUseCase is in Domain Layer, you can see Image 2.
I think GetAlbumListUseCase should be abstract class.
But I get "Cannot create an instance of an abstract class" error when I replace it with internal abstract class GetAlbumListUseCase(...).
1: What wrong with me? Does it cause by AlbumDomainModule.kt during Kodein ?
2: Should I use abstract class or interface in Use Case in Domain Layout?
GetAlbumListUseCase.kt
internal class GetAlbumListUseCase(
private val albumRepository: AlbumRepository
) {
sealed class Result {
data class Success(val data: List<Album>) : Result()
data class Error(val e: Throwable) : Result()
}
suspend fun execute(): Result {
// Due to API limitations search with custom phrase have to be performed to get albums
val phrase = "Jackson"
return try {
Result.Success(albumRepository.searchAlbum(phrase).filter { it.getDefaultImageUrl() != null })
} catch (e: IOException) {
Result.Error(e)
}
}
}
AlbumDomainModule.kt
internal val domainModule = Kodein.Module("${MODULE_NAME}DomainModule") {
bind() from singleton { GetAlbumListUseCase(instance()) }
bind() from singleton { GetAlbumUseCase(instance()) }
}
Image 2

