使用案例有 2 种方式执行相同的操作 [英] Use Case with 2 ways for the same action

查看:23
本文介绍了使用案例有 2 种方式执行相同的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题 1:使用 2 种方法执行相同操作来构建用例(或多个用例)的正确方法是什么?

Question 1: What is the correct way to build a Use Case (or more than one) with 2 ways to do the same action?

例如:

我在 iOS 应用中有 3 个屏幕:
1. 一个地图视图,可以长按"并有一个相机按钮.
2. 相机视图,如果用户在地图视图中点击相机按钮,则会显示该视图.
3. 位置/图钉编辑视图,如果用户长按"地图视图,或用户在相机视图中选择照片后显示.此编辑视图有一个保存按钮,用于实际创建带有照片和位置的地点(长按坐标或当前位置,以防按下相机按钮).

I have a 3 screens in an iOS app:
1. A map view, which can be "long pressed" and has a camera button.
2. A camera view, which is shown if the user taps the camera button in the map view.
3. A place/pin editing view, which is shown if the user "long presses" the map view, or after the user chooses a photo in the camera view. This editing view has a save button to actually create the place with a photo and the location (long press coordinate or current location in case the camera button was presses).

标题:创造场所基本流程:
1. 用户在地图上长按".
2. 应用删除临时图钉并显示地点编辑视图.
3. 用户编辑地点信息并按下保存按钮.
4. 应用创建地点并保存.

Title: Create Place Basic flow:
1. User "long press" on the map.
2. App drops a temporary pin and displays the place editing view.
3. User edits the place information and presses save button.
4. App creates the place and save it.

标题:创造场所基本流程:
1. 用户按下加号按钮.
2. 应用显示相机视图.
3. 用户拍照.
4. 应用使用当前位置和图片创建地点.

Title: Create Place Basic flow:
1. User presses plus button.
2. App displays camera view.
3. User takes a picture.
4. App creates place with current location and picture.

更新基于与 bhavik 交换的评论.

问题 2:(基于 bhavik 的回答)
所以我不需要一个演示者精确地为一个交互者,我可以有 1 个交互者和 3 个演示者/视图.

Question 2: (Based on bhavik's answer)
So I don't need one presenter for one interactor precisely, I can have 1 interactor and 3 presenters/views.

  1. 就我而言,我应该为地图设置一个演示者/视图,这是它的起点,
  2. 然后我应该为相机设置一个演示者/视图,以防用户点击相机按钮
  3. 和一个演示者/视图用于编辑视图,以防用户长按"或在用户从相机演示者/视图中选择照片并重定向到同一编辑视图之后.

正确吗?

问题 3:我的交互器边界方法是否应该始终返回 void?
在 bhavik 的例子中,他们返回了一些东西,但是在 VIPER blog鲍勃叔叔的视频 他们总是返回 void 并且结果以交互者调用的另一种边界方法的形式出现演示者/控制者.

Question 3: Should my boundary methods for the interactor always return void?
In bhavik's example they are returning something, but in the VIPER blog and the uncle Bob's video they always return void and the result comes in the form of another boundary method that the interactor calls on the presenter/controller.

问题 4: VIPER 方式不使用控制器,只使用 Presenter 与交互者交谈,当 Bob 叔叔的视频使用控制器和演示者与交互者进行不同的交互时.我应该采用哪种方法?

Question 4: The VIPER way does not use a controller, only a presenter to talk to the interactor, when the uncle Bob's video uses a controller and a presenter for different interactions with the interactor. Which approach should I take?

问题 5:如果我的用例类似于转到其他屏幕",它是否应该有一个交互器?由于当前视图会告诉它的演示者按下了什么按钮(要转到哪个视图),而当前演示者会告诉它的线框更改为另一个线框".

Question 5: If my Use Case is something like "Go to other screen", should it even have an interactor? Since the current view will tell its presenter what button was pressed (what view to go to) and this current presenter will tell its wireframe "change to this other wireframe".

推荐答案

问题 1: 使用 2 种方法来构建用例(或多个用例)的正确方法是什么行动?

Question 1: What is the correct way to build a Use Case (or more than one) with 2 ways to do the same action?

在 VIPER 设计中,您可以在同一个交互器中创建两种方法,适用于用例的每个主要和替代用例.

In VIPER design, you can create two methods in the same Interactor suitable for each primary and alternates of the use case.

问题 2:(基于 bhavik 的回答)所以我不需要一个演示者精确地为一个交互者,我可以有 1 个交互者和 3 个演示者/视图.

Question 2: (Based on bhavik's answer) So I don't need one presenter for one interactor precisely, I can have 1 interactor and 3 presenters/views.

根据我们的讨论和您的更新,我想我更好地理解了.

Based on our discussion and your updates, I think I understand it better.

  • Presenter/View 的交互不应超过 Interactor.
  • Presenter/View 可能根本不与任何 Interactor 交互,就像 CameraView 一样.
  • 它们是威世智中的中间视图.
  • 多个演示者/视图可以与单个交互者进行交互.
  • Interactor 不绑定到任何 Presenter.
  • Single Interactor 负责单一用例及其所有替代流程.1-1 关系.

所以,你应该有一个 EditPlacePresenter/View 用于 EditPlaceInteractor 传递数据 带或不带照片的地方数据.

So, you should have single EditPlacePresenter/View for EditPlaceInteractor that pass data Place data with or without Photo.

问题 3:我的交互器边界方法是否应该始终返回 void?

Question 3: Should my boundary methods for the interactor always return void?

在 bhavik 的例子中,他们返回了一些东西,但在 VIPER 博客和 Bob 叔叔的视频中,他们总是返回 void,结果以交互者在演示者/控制器上调用的另一种边界方法的形式出现.

In bhavik's example they are returning something, but in the VIPER blog and the uncle Bob's video they always return void and the result comes in the form of another boundary method that the interactor calls on the presenter/controller.

我认为您指的是以下从交互器接收结果的 Presenter 方法.

I think you are referring to the below Presenter method that receives results from the Interactor.

- (void)foundUpcomingItems:(NSArray*)upcomingItems

为了使上述工作正常进行,交互器将具有委托实例,这些实例将由演示者/控制器连接/修补以查找结果或数据.这意味着 Presenter/Controller 与 Interactor 相关联,或者它们的引用或返回函数指针在每个 Interactor 方法调用中传递.这是故意的吗?

For the above to work, the Interactor will have delegate instances that will be wired/patched through by the Presenter/Controller looking for result or data. This means the Presenter/Controller is tied to Interactor or their reference or return-function-pointer is passed in each Interactor method call. Is that by design?

我认为,Interactor 应该根据用例返回数据.例如,Interactor 应该返回 EditPlaceResult 成功或失败.

I think, Interactor should return data as per the use case. For example Interactor should return the EditPlaceResult with success or failure.

  • 如果成功,它应该包括保存的数据,例如地点 ID.
  • 如果失败,应包括失败原因.

这应该是用例的一部分.如果不是,那么它不应该返回任何东西.它将返回 void 并且 Presenter 将查询一个单独的 Interactor 以检查 Map Place 是否已成功添加.

This should be part of the use case. If not then, it should not return anything. It will return void and a separate Interactor will be queried by Presenter to check if Map Place was added successfully or not.

博客中的参考资料:

  • Presenter 包含视图逻辑,用于准备从交互器收到显示的内容.
  • Presenter 负责获取Interactor 返回的数据并对其进行格式化以供展示.
  • Presenter 接收来自 Interactor 的结果,并将结果转换为可高效显示在 View 中的形式.
  • Presenter contains view logic for preparing content for display as received from the Interactor.
  • Its up to the Presenter to take the data returned by the Interactor and format it for presentation.
  • The Presenter receives results from an Interactor and converts the results into a form that is efficient to display in a View.

问题 4: VIPER 方式不使用控制器,只使用 Presenter 与交互者交谈,当 Bob 叔叔的视频使用控制器和演示者与交互者进行不同的交互时.我应该采用哪种方法?

Question 4: The VIPER way does not use a controller, only a presenter to talk to the interactor, when the uncle Bob's video uses a controller and a presenter for different interactions with the interactor. Which approach should I take?

您需要为以下导航定义 VIPER 路线:

You need to define VIPER routes for following navigation:

  • 相机按钮:从MapView导航到CameraView(使用位置)
  • 长按:从MapView导航到EditPlaceView(使用坐标)
  • 拍摄的照片:从 CameraView 导航到 EditPlaceView
  • 保存地点:根据具体情况向交互器发送保存有/没有照片的地点的请求,如果成功则跳转回MapView
  • 返回按钮:基于导航堆栈返回上一个视图
  • Camera Button: Navigate from MapView to CameraView (Use Location)
  • Long Press: Navigate from MapView to EditPlaceView (Use Coordinate)
  • Photo taken: Navigate from CameraView to EditPlaceView
  • Save Place: Send Interactor a request to Save Place with/without Photo as the case may be and jump back to MapView if successful
  • Back Button: Back to previous View based on Navigation Stack

根据 VIPER 博客,演示者和线框使用视图控制器和导航控制器.

As per the VIPER blog, view controllers and navigation controllers are used by Presenters and Wireframes.

VIPER Wireframe 处理导航并使视图控制器变得精益、平均、视图控制机器.

VIPER Wireframe handles Navigation and makes view controllers become lean, mean, view controlling machines.

基本上线框抽象掉导航控制器,而是提供路由定义.

Basically Wireframe abstracts away navigation controller and instead provides route definition.

线框

  • 拥有 UINavigationController 和 UIViewController
  • 负责创建View/ViewController并在窗口中安装
  • 路由在 Wireframes 中定义并包含导航逻辑,用于描述以何种顺序显示哪些屏幕

演示者

  • 使用线框进行导航
  • 为了保持视图控制器精简,VIPER 需要让视图控制器在用户执行某些操作时通知相关方 - 演示者来这里!
  • 视图控制器不应该根据这些操作做出决定,但它应该将这些事件传递给可以做的事情 - 演示者应该做出决定!

问题 5:如果我的用例类似于转到其他屏幕",它是否应该有一个交互器?由于当前视图会告诉它的演示者按下了什么按钮(要转到哪个视图),而当前演示者会告诉它的线框更改为另一个线框".

Question 5: If my Use Case is something like "Go to other screen", should it even have an interactor? Since the current view will tell its presenter what button was pressed (what view to go to) and this current presenter will tell its wireframe "change to this other wireframe".

没有.导航作为用例的一部分可能不需要交互器.它只是过渡.目标 Presenter 可能需要一个交互器.例如,CameraView/Presenter 不需要 Interactor 但 EditPlaceView 需要保存位置.

No. Navigation as part of use case may not need Interactor. It is transition only. The target Presenter may need an Interactor. For example, CameraView/Presenter does not need Interactor but EditPlaceView needs to save the place.

总体:架构模式背后的思想是将给定的软件应用程序划分为相互关联的部分,以便将信息的内部表示与向用户呈现或接受信息的方式分开.MVC、MVP、MVVM、VIPER 都专注于以一种或另一种方式隔离视图、逻辑和导航.

Overall: The idea behind architectural patterns is to divide a given software application into interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user. MVC, MVP, MVVM, VIPER all focus on isolating View, Logic and Navigation in one way or other.

架构模式在他们打算分解的内容方面受到限制.我们必须明白,架构模式不会分解或隔离一切.此外,如果一种架构模式将某些职责委派给某个部分,其他的则可能根本不这样做或将多个职责分配给单个部分.

Architectural patterns are limited in what they intend to decompose. We have to understand that architectural patterns do not decompose or isolate everything. Also if one architectural pattern delegates certain responsibilities to certain part, other does not do that at all probably or assign multiple responsibilities to single part.

我们可以扩展或限制隔离和分解,以证明原因是合理的,并且不会强加不必要的超出成本的关注点分离.您可以选择使用导航控制器,并且您的演示者可以在没有定义线框路由的情况下依赖它们.然后这些控制器将负责屏幕之间的导航.

We are allowed to extend or limit the isolation and decomposition to the extent that it justifies the cause and does not impose unnecessary separation of concerns that overrun the cost. You can choose to use navigation controllers and your presenter can take dependency on them without Wireframe routes defined. These controllers then will be responsible for the navigation between screens.

这篇关于使用案例有 2 种方式执行相同的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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