Member-only story

Unlocking the Power of Mappers in Android: Simplifying Data Transformation in Clean Architecture

SUMIT KUMAR
6 min readJun 4, 2023

What are mappers and how do mappers facilitate data transformation between layers (Data and Domain) and contribute to achieving a CLEAN architecture in Android development?

In this article we will explore the significance of mappers in Android development and their integral role in implementing Clean Architecture. Learn how mappers facilitate data transformation between layers, enhance code maintainability, and improve testability. You will be having practical examples of mapper implementation and unlock the potential to streamline your Android app development with clean and efficient architecture.

CONTENTS

  • NEED OF MAPPERS(THEORY)
  • ABSTRACT
  • IMPLEMENTATION
  • THANKS AND REGARDS

What is the need of mappers?(you can jump to abstract if don’t want detail).

The need for mappers arises from the desire to achieve a CLEAN (CLear, ENcapsulated) architecture in Android development. Mappers play a crucial role in facilitating data transformation between layers, specifically between the Data layer and the Domain layer. Here are the key reasons why mappers are needed:

  • Separation of Concerns

SUMIT KUMAR
SUMIT KUMAR

Written by SUMIT KUMAR

SDE(Android) || Ex-Ingenium || Modern Mobile Developer📱

Responses (5)

Write a response

It's easier to use kotlin extension functions to do that.

class MyObjDto(
val parm1: String,
val parm2:Boolean
)

class MyObjModel(
val parm1:String,
val parm2:Boolean
)

fun MyObjDto.toDomain(): MyObjModel = MyObjModel(parm1,parm2)...

Small suggestion, having Mappers in the domain layer implies that domain layer knows about data layer, which contradicts clean arch layers separation - It needs to moved to the data layer/package/module

To take advantage of the Kotlin sintax sugar you could make your mapper Interface a functional interface.

I've had this conversation in the past. let and run extension functions look like mappers.

IMHO just taking the definition of let or run…