According to the MVVM Architecture, the use of a data mapper class is mandatory as it maps the entity to the domain which can be used in the presentation layer. While using coroutines, do we explicitly need to create a Mapper Class. For example this is the DataMapper class :
class PermissionDataMapper @Inject constructor() {
fun mapEntityToDomain(permissionEntity: PermissionEntity): PermissionDomain {
return PermissionDomain(
permissionName = permissionEntity.roleDesc,
permissionId = permissionEntity.roleId
)
}
fun mapEntityListToDomainList(permissionEntityList: List<PermissionEntity?>): List<PermissionDomain> {
return permissionEntityList.map { permissionEntity ->
mapEntityToDomain(permissionEntity!!)
}
}}
Which is further used inside a DataRepositoryClass which maps the entity list to a domain list :
override fun getSharePermissions(): Observable<List<PermissionDomain>> {
return userDataSourceFactory.retrieveRemoteDataSource().getSharePermissions().map {
return@map permissonsDataMapper.mapEntityListToDomainList(it)
}
}
Do we need to follow this same pattern if we use coroutines? Or does the mapping of domain to entity or entity to domain happens in the background automatically ?
Aucun commentaire:
Enregistrer un commentaire