android10 / Android-CleanArchitecture

This is a sample app that is part of a series of blog posts I have written about how to architect an android application using Uncle Bob's clean architecture approach.
Apache License 2.0
15.52k stars 3.32k forks source link

Why transform User in the User to UserModel in the presentation #228

Open Deep21 opened 7 years ago

Deep21 commented 7 years ago

Hello everyone, Why we are transform the User class to UserModel, we could pass just the User instance afterall to the view. Why add this complexity ?

Thank you

alexandru-calinoiu commented 7 years ago

The way I think about it is that User is a dto (data transfer object), should be a simple pojo, it will responsible for passing info back and forward between my app and an external service like a database or an api.

UserModel on the other hand will contain some presentation logic, manipulate the raw User data to be presentable and consumed by the View layer, lately I use bindings between this models and the views.

mibrahimdev commented 7 years ago

it's for separating the modules for a testability perspective making the system decoupled, and as @android10 mentioned in his blog post

It is worth mentioning that each layer uses its own data model so this independence can be reached (you will see in code that a data mapper is needed in order to accomplish data transformation, a price to be paid if you do not want to cross the use of your models over the entire application).

Deep21 commented 7 years ago

thank you

zvvadim commented 7 years ago

Thank you, great job.

2017-03-30 21:37 GMT+03:00 Deep21 notifications@github.com:

thank you

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/android10/Android-CleanArchitecture/issues/228#issuecomment-290504849, or mute the thread https://github.com/notifications/unsubscribe-auth/ALdsRH1DNrV-tSmVCIqb4pJoHmyJCnNLks5rq_Z0gaJpZM4MkXe5 .

lbensaad commented 7 years ago

This question is also discussed here #72 and there are interesting comments.

jemshit commented 7 years ago

This can be closed