How much should presenters know about the view?

89 views
Skip to first unread message

Acácio Veit Schneider

unread,
Nov 29, 2022, 7:31:09 AM11/29/22
to Clean Code Discussion
I have a Flutter mobile application where I do request data from the backend, and each individual record of this data have it's own identifier and category. For each of these identifiers I want to redirect the user to the correct page of the app. An example:

1. User enter the page, and we request the data
2. Data arrives and we present it.
3. When clicking at each item, we should redirect the user to the appropriate page of that item.

Question 1) Where should the route definition be?
Currently I created a Widget and made a switch case on the identifiers to define the route of each one click.

But shouldn't this be done already in the presenter, so the view would only display it and create the callbacks to redirect it with the given route? My concern about it is that then the presenter would know too much about the View, or am I wrong?
----

Question 2) Each of those items that I mentioned have their priority, and in the view each priority is displayed in their own way, like Urgent priority is displayed in red and so on...
Should presenter also define these colors for the view? The problem is that this Color it's an object from the Flutter Framework which I would like to avoid in this layer...

Thank you!
Acácio.

Łukasz Duda

unread,
Nov 30, 2022, 4:13:08 AM11/30/22
to Clean Code Discussion
Hi Acácio,

In the example presenter https://github.com/cleancoders/CleanCodeCaseStudy/blob/master/src/cleancoderscom/usecases/codecastSummaries/CodecastSummariesPresenter.java passes permalink to the view https://github.com/cleancoders/CleanCodeCaseStudy/blob/master/src/cleancoderscom/usecases/codecastSummaries/CodecastSummariesViewImpl.java. View implementation uses template and adapts permalink to show hyperlink with appropriate URL https://github.com/cleancoders/CleanCodeCaseStudy/blob/master/resources/html/details.html.

In other words abstract category, identifier and priority returned to presenter can be used as decision and further adapted in to instruct flutter to show appropriate link and route to selected view. In my opinion routing could be implemented in flutter (view implementation in frameworks layer https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html). Presenter (interface adapters) should not touch framework directly.

I like the example of presenter using view through view interface at the end of Agile Software Development: Principles, Patterns, and Practices book.

Regards
Łukasz

Acácio Veit Schneider

unread,
Nov 30, 2022, 12:34:54 PM11/30/22
to Clean Code Discussion
Hi Łukasz, thank you very much for answering it :)

I think I got your point, so you are saying that the presenter can return a route but the view will format it to let the flutter framework do the navigation properly at the end, right?

And do you see any problem in passing the priority identifier (which comes from the entities) along the layers to make specific decisions based on that? Like displaying the item in Red background when it's urgent, and displaying it in white background when it's low priority.

Since it's only an identifier and not a business object, my guess is that's ok, but I'm not 100% sure of it.

Regards
Acácio.

Łukasz Duda

unread,
Dec 1, 2022, 4:43:35 PM12/1/22
to clean-code...@googlegroups.com
Hi Acácio,
Right. Let's say that the view shows tasks list. The presenter could receive
{ tasks: [{ id: "bf857532-6513-4c95-8ac3-531f35a42535", priority: "low" }] }
I imagine that view implementation could display list of task widgets, colored by priority, that would pass id arguments to a named route "/tasks" https://docs.flutter.dev/cookbook/navigation/navigate-with-arguments.

One thing to consider... I don't see much responsibility of presenter or business rules here. The question is, whether you gain anything trying to separate layers in such simple case. In my opinion the Clean Architecture pays off better if you have business rules.

Regards
Łukasz

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/clean-code-discussion/da0eb5dc-64c7-429f-ac81-79c44119246fn%40googlegroups.com.

Acácio Veit Schneider

unread,
Dec 6, 2022, 9:58:31 AM12/6/22
to Clean Code Discussion
Hi Łukasz,

Thank you very much for your responses, it helped a lot to clear out some things :)

Regards,
Acácio.
Reply all
Reply to author
Forward
0 new messages