Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this Object Mapping or Domain Logic? #268

Open
mlorenz2 opened this issue Feb 26, 2018 · 3 comments
Open

Is this Object Mapping or Domain Logic? #268

mlorenz2 opened this issue Feb 26, 2018 · 3 comments

Comments

@mlorenz2
Copy link

Hi, maybe someone can help me.
I'm discussing with my co-workers about follow problem:
We have an UseCase with fetches any AWS Endpoint which delivers an object, containing several fields and an unresolved key. This key has to be resolved to an image url. To get this url we have to fetch another endpoint with this key. My question is how to do this correctly with clean architecture? In our mind there are several options:

  1. One UseCase handles this: We fetch the first endpoint, where we get a business model with the aws key and then fetch the second service to resolve the key to the imager url
  2. For SOLID reasons, write another UseCase which resolves the key and put it in to the origin UseCase from 1)
  3. See the resolving of a key to an imageurl not as business logic, but as object mapping. Therefore we attach the service which resolves the key to the object mapping class, where we map the incoming aws object to our business model.
  4. Same as 3), but the object mapper doesn't call the service itself, but a UseCase which uses the service (Us the UseCase in 2)). Then we would have crossing all the boundaries from Clean Architecture again (which is good)

But am I allowed to talk to an other service which is on the same clean architecture layer (green layer of the clean architecture picture) (Option3)? In my opinion actually not, because I'm also not allowed to talk from presenter to any other service. But we are allowed to call UseCases in repositories or other services (such as services laying in the infrastructure package) (Option4)

Speaking in a metaphor: We do have 2 tables in a database. The first one contains partially the data we want and in the second there are the resolved image urls. What we want to do now is a join between these tables to get the all the necessary data (Which is the data from table 1 with the resolved key from table 2)

Hope my problem is clear and thank you for any help :)

@crjacinro
Copy link

Maybe you can create one use case with observables? I dont know how to implement this but my idea would be to invoke both observables and merge them .

@mlorenz2
Copy link
Author

Hi,
thank you for your answer. So basically what I understand from your answer is to use 1) from above. Every repo/service returns observables anyway. The problem with 1) and 2) is, that we create a business model (object with aws key inside) which we never use or want to have. The only business model we want to have is actually the object with the resolved image url

@trietbui85
Copy link

One UseCase handles this: We fetch the first endpoint, where we get a business model with the aws key and then fetch the second service to resolve the key to the imager url

The problem with 1) and 2) is, that we create a business model (object with aws key inside) which we never use or want to have

I prefer solution 1, because image url belongs to current business model, thus the UseCase should return full model (with image as well). Having extra fields in that model is not a problem, because in Presenter layer, you must convert that business model into a clean UI model (with just image url but not extra fields) (as BufferApp did)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants