mercredi 4 août 2021

converting entities into model in clean architecture in dart

As in clean architecture, we have to define the Entities in Domain layer and Models in Data layer. Now the issue that i am facing is in converting the entities into models when we are passing that as a request object in repositories.

here is the diagram which depicts the relationship amongst the entities (in brown) and models (in green).

Now, what is the simplest way to convert the entities to model in dart because implementing a mapper and then copy one field from another field seems a very tedious job and when there are nested objects in class (i.e. UserProfile data in below diagram) takes lots of time. so is there any library that exists or a better approach that could seamlessly convert entities to model.

abstract class Mapper<E, D> {
  D mapFromEntity(E type);

  E mapToEntity(D type);
}

entity to model relationship

Aucun commentaire:

Enregistrer un commentaire