清洁架构 - Robert Martin - 如何连接用例 [英] Clean Architecture - Robert Martin - How to connect use cases

查看:20
本文介绍了清洁架构 - Robert Martin - 如何连接用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施 Robert Martin 描述的.

解决方案

我对 Viper 了解不多,因此无法对此发表评论.然而,系统的总体状态应该保存在实体对象中并由交互者操作.GUI 的详细状态(选择矩形等)应由控制器和演示者之间的特殊连接管理.

就您而言,有两个屏幕.地图和地点编辑器.单击地图会导致调用 placePinController.它收集点击的位置和任何其他上下文数据,构造一个 placePinRequest 数据结构并将其传递给 PlacePinInteractor,后者检查 pin 的位置,在必要时验证它,创建一个 Place 实体来记录 pin,构造一个 EditPlaceReponse对象并将其传递给 EditPlacePresenter,后者会显示地点编辑器屏幕.

如果在地点编辑器屏幕上单击 Done 按钮,它会调用 EditPlaceController,后者将编辑的数据收集到 EditPlaceRequest 数据结构中,并将其传递给 EditPlaceInteractor.等等.

您特别询问了引脚的 GUID.这将由 Place 实体创建并传递回 editPlacePresenter PlacePinInteractor.

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:

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.

解决方案

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.

这篇关于清洁架构 - Robert Martin - 如何连接用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆