Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean Architecture - Robert Martin - How to connect use cases

I'm trying to implement the Clean Architecture described by Robert Martin. More specifically I'm using VIPER which is an iOS version of Clean Architecture.

The problem I have is as follows:

The user starts looking at a map with places (pins) on it. If he clicks a button, a pin is dropped and he is taken to another view to create (or edit if it was a click to an existent pin) the place (or cancel). In this other view, the user can edit the place's information and then click "back" or "done" (or "edit"). If he clicks "done", the PlaceDetailsViewController sends a message to the PlaceDetailsPresenter with the place information and the PlaceDetailsPresenter uses the CreatePlaceInteractor to create the place. This interactor returns the GUID which is used to identify the place.

If the user clicks back before creating the place, he gets back to the map and the dropped pin goes up and away (since it has no GUID, it is a new place and goes away). If he clicks back after creating, the pin stays there (because it should have a GUID).

How should I connect all that and where should the place information (including GUID) be stored? To clarify a little bit more:

  1. Who should inform the MapPresenter that the pin stays there or goes away? Is it the PlaceDetailsPresenter or should I pass this information to the PlaceDetailsWireframe -> MapWireframe -> MapPresenter -> MapView ?
  2. Before going back, where should this GUID be stored, in the PlaceDetailsPresenter or in the PlaceDetailsViewController?

Right now that's what I have: enter image description here

EDIT:

Basically I think the problem is that VIPER came from Robert Martin's Clean Architecture and he comes from a Web (Rails) background, so he doesn't think much about state (or don't specify it in his talks).

Which is mainly my question, where should the state be stored, how should the different modules communicate, should it be through the Wireframe, or through the database, or through the interactors, or through the Presenters communicating with each other like here https://github.com/objcio/issue-13-viper-swift.

like image 916
Rodrigo Ruiz Avatar asked Mar 06 '15 05:03

Rodrigo Ruiz


1 Answers

I don't know much about Viper, so I can't comment about that. However, the gross state of the system should be held in the entity objects and manipulated by the interactors. The detailed state of the GUI (selection rectangles, etc) should be managed by a special connection between the controller and the presenter.

In your case there are two screens. The map, and the place editor. Clicking on the map causes either the placePinController to be invoked. It gathers the location of the click, and any other contextual data, constructs a placePinRequest data structure and passes it to the PlacePinInteractor which checks the location of the pin, validates it if necessary, create a Place entity to record the pin, constructs a EditPlaceReponse object and passes it to the EditPlacePresenter which brings up the place editor screen.

If the Done button is clicked on the place editor screen it invokes the EditPlaceController which gathers up the edited data into an EditPlaceRequest data structure and passes it to the EditPlaceInteractor. etc..

You specifically asked about the GUID of the pin. That would be created by the Place entity and passed back to the editPlacePresenter PlacePinInteractor.

like image 104
Robert Martin Avatar answered Oct 06 '22 13:10

Robert Martin