Home > Enterprise >  Does the Data Mapper layer is really required in MVVM clean architecture?
Does the Data Mapper layer is really required in MVVM clean architecture?

Time:02-24

I have seen in some codebases that they are using mapper layer with usecase and repo layers. We can have the mapper logic inside the use case layer right? or is there any specific reason why we need that layer?

CodePudding user response:

Yes, you can, but it's usually a good idea to user a mapper. Mapper is not MVVM specific, the reason to use the mapper pattern is to isolate the logic making it easier to test and reuse the conversion logic in other classes if necessary.

CodePudding user response:

It's a kind of tradeoff when you are designing your architecture. In principle, application architecture is a code breakdown process by logical groups. Logic defines groups as related entities with the same level of abstraction. So in applications, logical groups are the view layer, business use-case layer, data management layer. If you want to break down these layers into their logical sub-components it is possible but it reduces code readability and could slow down development. on the other hand, it gives you the ability to test sub-components. So it's really a tradeoff that you have to deal with when designing your architecture. mapper is an example of breaking down the domain layer further and coordinator is an example of breaking down the view layer further.

  • Related