Android Clean Architecture
Creating the data models for the data layer
Up next
Previous
About
The Data layer allows us to abstract the sources of the data that our application uses. In this lesson, we’re going to begin building our data layer by creating the data models for use in its operations, as well as creating the mapper classed used to map between this representation and the Domain layers representation of the project class.
Instructor
Links
Comments
I would use this more generic Entity Mapper which also handles lists
```
* Interface for mapping [D] domain entity to data source entity types and vice versa.
* @param D Domain entity type
* @param R Data entity type either remote or local
/
interface EntityMapper {
/*
* @return Function that maps [R] data entitiy to [D] domain entity
*/
fun toDomainEntity(): (R) -> D
/**
* Map [List]<[R]> list of data entities to [List]<[D]> list of domain entities
* @return Function that maps [List]<[R]> list of data entities to [List]<[D]> list of domain entities
*/
fun toDomainEntityList(): (List) -> List = { it.map(toDomainEntity()) }
/**
* @return Function that maps [D] domain entitiy to [R] data entitiy
*/
fun toDataEntity(): (D) -> R
/**
* Map [List]<[D]> list of domain entities to [List]<[R]> list of data entities
* @return Function that maps [List]<[D]> list of domain entities to [List]<[R]> list of data entities
* @return Function that maps [D] domain entitiy to [R] data entitiy
*/
fun toDataEntityList(): (List) -> List = { it.map(toDataEntity()) }
}
```
Lessons in Android Clean Architecture















































































