Sorting: interactor vs. presenter

249 views
Skip to first unread message

Jeff Gilbert

unread,
Mar 24, 2014, 12:35:27 PM3/24/14
to clean-code...@googlegroups.com
Hey y'all,

In trying to follow Uncle Bob's Clean Architecture, I can't decide if sorting should happen in the Interactor or the Presenter.

For example, my Interactor retrieves a list of items from a web service. Should I sort them in the Interactor and pass the sorted objects though the boundary to the Presenter? Or, should I allow the Presenter to sort the objects? I know that the Presenter is the appropriate place to apply formatting (e.g. date or currency formatting).

How do you determine if sorting is part of the use case (i.e. the Interactor) or part of the UI (i.e. the Presenter)?

Thanks,
Jeff Gilbert

James Green

unread,
Mar 24, 2014, 12:53:29 PM3/24/14
to clean-code...@googlegroups.com
Feels presentation level to me. Most UIs would probably include sorting functionality for lists of data.

That said, if the UI expects sorted data because of a pageing interface supplied by the interactor it should be able to specify sort criteria and expect data already... 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.

Caio Fernando Bertoldi Paes de Andrade

unread,
Mar 24, 2014, 9:14:31 PM3/24/14
to clean-code...@googlegroups.com
In other words:

If your UI gets all the entries and plays with sorting and ordering itself, then the interactor always responds with all entries and doesn’t have to know anything about sorting or ordering.

If your UI gets only an appropriate amount of entries to display, it’s your interactor’s responsibility to respond with a specific subset of entries, based on sorting and ordering criteria.

Cheers,
Caio

James Green

unread,
Mar 25, 2014, 4:51:43 AM3/25/14
to clean-code...@googlegroups.com
The interactor has no idea whether the presenter can sort. It therefore only makes sense that the request object that interactor exposes has sort parameters where applicable. If the presenter wants to re-sort, it therefore may.

Jeff Gilbert

unread,
Apr 1, 2014, 3:49:31 PM4/1/14
to clean-code...@googlegroups.com
Thanks for the feedback, James.

For the current case I am considering, the web service does not supply any sorting, but we do not want the user to choose how to sort; there is one canonical sorting to apply. For this, I will apply the sorting in the interactor, since it seems like it is the customer that is defining the one true way to sort.

Jeff


On Monday, March 24, 2014 11:53:29 AM UTC-5, James Green wrote:
Feels presentation level to me. Most UIs would probably include sorting functionality for lists of data.

That said, if the UI expects sorted data because of a pageing interface supplied by the interactor it should be able to specify sort criteria and expect data already... sorted.
On 24 March 2014 16:35, Jeff Gilbert <jeff.g...@mutualmobile.com> wrote:
Hey y'all,

In trying to follow Uncle Bob's Clean Architecture, I can't decide if sorting should happen in the Interactor or the Presenter.

For example, my Interactor retrieves a list of items from a web service. Should I sort them in the Interactor and pass the sorted objects though the boundary to the Presenter? Or, should I allow the Presenter to sort the objects? I know that the Presenter is the appropriate place to apply formatting (e.g. date or currency formatting).

How do you determine if sorting is part of the use case (i.e. the Interactor) or part of the UI (i.e. the Presenter)?

Thanks,
Jeff Gilbert

--
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-discussion+unsub...@googlegroups.com.

Jeff Gilbert

unread,
Apr 1, 2014, 3:50:41 PM4/1/14
to clean-code...@googlegroups.com
Thanks, Caio.

You raise some good points. It looks like the choice will have to be made on a case by case basis.

Jeff


On Monday, March 24, 2014 8:14:31 PM UTC-5, Caio Fernando Bertoldi Paes de Andrade wrote:
In other words:

If your UI gets all the entries and plays with sorting and ordering itself, then the interactor always responds with all entries and doesn’t have to know anything about sorting or ordering.

If your UI gets only an appropriate amount of entries to display, it’s your interactor’s responsibility to respond with a specific subset of entries, based on sorting and ordering criteria.

Cheers,
Caio
On 24 Mar 2014, at 13:53, James Green <james.m...@gmail.com> wrote:

Feels presentation level to me. Most UIs would probably include sorting functionality for lists of data.

That said, if the UI expects sorted data because of a pageing interface supplied by the interactor it should be able to specify sort criteria and expect data already... sorted.
On 24 March 2014 16:35, Jeff Gilbert <jeff.g...@mutualmobile.com> wrote:
Hey y'all,

In trying to follow Uncle Bob's Clean Architecture, I can't decide if sorting should happen in the Interactor or the Presenter.

For example, my Interactor retrieves a list of items from a web service. Should I sort them in the Interactor and pass the sorted objects though the boundary to the Presenter? Or, should I allow the Presenter to sort the objects? I know that the Presenter is the appropriate place to apply formatting (e.g. date or currency formatting).

How do you determine if sorting is part of the use case (i.e. the Interactor) or part of the UI (i.e. the Presenter)?

Thanks,
Jeff Gilbert


--
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-discussion+unsub...@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.

--
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-discussion+unsub...@googlegroups.com.

Lee

unread,
Apr 1, 2014, 4:18:08 PM4/1/14
to clean-code...@googlegroups.com
Hi

I would initially give the interactor the ability to sort based on parameters supplied in the request, including a default of returning the data as supplied by the web service, effectively turning sorting off in the interactor, i would consider it more like a retrieval order, hopefully that would also help protect against future changes to the interactor should requirements change, and could allow the UI to be changed to something else whilst leaving the sorting (retrieval order) in place. however should in the future there be a requirement for the user to be able to change the order he's viewing the data in, i'd possibly implement that in (or nearer) the UI so that the interactor isn't invoked again to retrieve the same data again just to change the order, i'd probably consider that type of on the fly sorting the responsibility of the UI. i suppose it depends how volatile the data is.

Hope that helps
Lee

Reply all
Reply to author
Forward
0 new messages