Mapping a Domain Model to a Network Entity on Android

preview_player
Показать описание

In this video I show you how map an android "domain model" to a "network entity". Generally speaking I think it's always a good idea to build models for every data source in your projects. The data from the network might not match the data from the domain. And the data from the cache might not match the data from the domain. It is likely to be slightly different. Building custom mappers will help when it comes to testing and scaling your apps.

Follow me:
.
.
Рекомендации по теме
Комментарии
Автор

At 10:00 I'd like to let you people know that instead of writing `?: listOf()` you could instead write `.orEmpty()`. Feels a bit nicer to me, and it has some other benefits too, not in this case, but it's good to know anyway.

GakisStylianos
Автор

Quick tip, that has ended up saving me a lot of time: If you have the curser on a word in the code, you can press Ctrl + J, and it will highlight subsequent instances of the word, one per time you press the shortcut. Then, when you highlighted all the words you want, you can edit them all at once, and finally press escape to exit "multi line editing". When I saw you changing all the "entity" objects to "domainModel" one at a time, I thought to mention it. Maybe you already know, but here it is :) Thanks for the amazing content

emil_fa
Автор

I'm following this course just after 3 months it was released, and so much has changed in just 3 months.
Need to follow the course and doc simultaneously.
Damn you Android

yogenp
Автор

I aprecciate how you always go back to a whiteboard to explain the concepts at a higher level before you deep dive into code. It's very easy to follow your reasoning.

CommanderSteps
Автор

*The BEST android courses in the world* confirmed

samha
Автор

Always Like before watching videos. enough engagement with Mitch.

MuhammadNaveed
Автор

Although I am late in this course but still "THIS IS YOUR ENGAGEMENT✨✨✨" .Keep it safe.

shashankdaima
Автор

Well that is good piece of code.
I did the same thing using for each loop for transforming from one model into another. Map serves the same purpose.
Good work

shehramjamil
Автор

thank you for the video, it was great as usual!
I was a bit disappointed for not having the English subtitles.

biancacionca
Автор

Why don't you just create a static method inside the view's model class that constructs that model from a different model (say a network model)?

FckYouPlz
Автор

Thanks mitch you're always the best mentor for me in this universe. Day by day I always learn new things from you. You're really a gem man.

ShethMilan
Автор

i didn't quire understand what does entity mapper and network mapper do, i could understand the conversion between both but why do we need mappers here, thank you for the answer in advance

AlgeriaHere
Автор

Why should we use interface() instead of simple methods in the activity?

alitonoliveira
Автор

thanks for this Mitch, still seeing this in 2022

osezelejohn
Автор

Mitch, I feel that mappers are used to inject business logic to the Entity Data so that we show refined data in the UI. I also feel that the fields in Domain Model should be non-null as they would be used by UI. Am I right?

ramakrishnavjoshi
Автор

It's a good idea on design phase for protect your UI layer and for any purpose. I will suggest to mapping object for each layer following this sample if you design the object good enough and you have time to maintenance it. I found this pattern is hell for me on my side job (maintenance the existing object from the other)because they create multiple object with same properties and each object can change into the another Obj. It cause to updating more than 20file after add field just from 1 endpoint. Hope this helpful for someone.

siwarakdeekaew
Автор

Thanks for the video, I also prefer custom mapper mechanism to the automatic one, but I prefer to do the map as extensions functions on business and network entities.

nonofce
Автор

how to map to domain for single data or not List?

bangtiray
Автор

why is auto generated subtitle is korean ???

seyedmohammedjavadsadathos
Автор

Why not use extention functions for mappers?

pejmanazad