Where to order? Should response models be ordered?

112 views
Skip to first unread message

Jeroen De Dauw

unread,
Dec 8, 2015, 9:59:38 AM12/8/15
to Clean Code Discussion
I have a system where I have Use Cases / Interactors that pass Response Models to Presenters. It is not clear to me where ordering of data should happen. Should it be done by the Presenter, or should the Presenter get a Response Model that already includes the correct order as determined by the Interactor?

My initial thoughts on this where that sorting is a presentation concern, and should thus not be in the Interactor or Response Model. However, I cannot imagine using a different Presenter for the same Use Case / Interactor and have a different sort. Furthermore, while I'm not planning on adding any such thing, one can imagine adding sorting information to the Request Model, in which case the Response Model would certainly need to be sorted.

Caio Fernando Bertoldi Paes de Andrade

unread,
Dec 8, 2015, 11:18:32 AM12/8/15
to clean-code...@googlegroups.com
Will you use pagination together with sorting?

How smart can be your delivery mechanisms? Classical Request/Response WebApp, SPA or Native (Desktop/Mobile)?

Caio


Em 8 de dez de 2015, à(s) 12:59, Jeroen De Dauw <jeroen...@gmail.com> escreveu:

I have a system where I have Use Cases / Interactors that pass Response Models to Presenters. It is not clear to me where ordering of data should happen. Should it be done by the Presenter, or should the Presenter get a Response Model that already includes the correct order as determined by the Interactor?

My initial thoughts on this where that sorting is a presentation concern, and should thus not be in the Interactor or Response Model. However, I cannot imagine using a different Presenter for the same Use Case / Interactor and have a different sort. Furthermore, while I'm not planning on adding any such thing, one can imagine adding sorting information to the Request Model, in which case the Response Model would certainly need to be sorted.

--
The only way to go fast is to go well.
---
You received this message because you are subscribed to the Google Groups "Clean Code Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discu...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at http://groups.google.com/group/clean-code-discussion.

Jeroen De Dauw

unread,
Dec 8, 2015, 11:46:31 AM12/8/15
to Clean Code Discussion
Thanks for the quick reply Caio.


> Will you use pagination together with sorting?

Actually the scenario where I ran into this question does not involve any collection the user can paginate through. It is a collection within a single document. So the answer is no.

(The scenario being the sorting of the elements in the "data" section by their keys in http://queryr.wmflabs.org/api/items/Q64)


> How smart can be your delivery mechanisms? Classical Request/Response WebApp, SPA or Native (Desktop/Mobile)?

It is a REST API.

Caio Fernando Bertoldi Paes de Andrade

unread,
Dec 8, 2015, 11:53:41 AM12/8/15
to clean-code...@googlegroups.com
Sweet.

If it only makes sense to return this data in one order, like you mentioned in the previous email, then just make it be the default behaviour for the usecase, and the presenter has no business with it. Write a test for it at the usecase level, UB and Micah did just this in the Java Case Study, so you can refer to that.

OTOH, if the user might manipulate this sorting in some way but it doesn’t make you go fetch data again, you can leave the sorting behaviour in the presenter, given it’s purely a presentation rule.

What do you think?

Caio

Reply all
Reply to author
Forward
0 new messages