Use Case with 2 ways for the same action

后端 未结 4 1798
梦谈多话
梦谈多话 2021-02-10 09:57

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

For example:

I have a 3 screens in

4条回答
  •  旧巷少年郎
    2021-02-10 10:35

    Question: What to do when 2 use cases are related to the same presenter/view? For example, I have a presenter/view that

    • Checks if user is logged in and also
    • Asks for user location authorization before doing anything else.

    Answer

    Use Case Modelling

    It seems that you are dealing with non-trivial use-case modelling scenarios.

    "Check user-login" does not need use case. Similarly, if location authorization is not being updated as part of configuration settings, then it is also not a use-case. They are not good candidates for use-case modelling but rather preconditions or "steps" in other complex use cases. I think they are more like preconditions then "steps" and certainly not individual "use-cases" themselves.

    Preconditions should be accompanied by use-case exceptions and non-trivial "steps" hints use-case-reuse via include-dependencies. If preconditions fails, you can provide appropriate messages and options to fulfil those conditions. For complex steps, one use case redirect to other use-case.

    The idea is to either opt for exceptions that will terminate the use case with valid message on failed preconditions OR include other use-cases that will ask user to log-in first and resume current use case.

    The goal is to break down complex requirements and re-use them. Quoting from Use Case Reuse - Include Dependency. "You use include dependencies whenever one use case needs the behavior of another. Introducing a new use case that encapsulates similar logic that occurs in several use cases is quite common."

    In VIPER Way

    • Interactors should know about other Interactors if required.
    • Rules and preconditions should validated in Interactors or in Entities as required.
    • Interactors should return appropriate data for Presenters.
    • Presenters should NOT know about other Presenters that are part of other use cases.
    • Presenters should send requests to Wireframe.
    • Wireframe should take care of appropriate navigation to different Views.

    Thus,

    • CreatePlaceInteractor should take dependency on UserLogInInteractor and LocationAuthorizationInteractor and call them when necessary.
    • Or CreatePlaceInteractor should send back data that Presenter can interpret and ask Wireframe to launch UserLoginPresenter and/or LocationAuthorizationPresenter.

    This will involve carefully designed interactions and navigation for control flow and data flow using Interactors, Presenters and Wireframes. In the process, you will be challenging lot of core assumptions and hidden unhandled system behaviour.

    Since other use cases may also include user-login or authorization-access to finish their task, these use cases should be included but not necessarily executed all the time - conditional function call to UserLogInInteractor and LocationAuthorizationInteractor. If user is logged in and authorization access is already allowed, they will be skipped. When user chooses CameraView, check for user-login and location access. When user chooses EditView directly from MapView, check for for user-login only.

    I think you should implement precondition logic into your Interactors and Presenter can use it to make Presentations and Navigations related decisions.

    Considering following list of Use Cases:

    • "UC001: User Log In".
    • "UC002: Get Location Access Authorization".
    • "UC003: Show Map".
    • "UC004: Create Place on Map".

    UC004: Create Place on Map (With Preconditions)

    Preconditions:

    1. User is logged in.
    2. Location Access has been authorization.

    Steps:

    1. If preconditions are NOT met, run appropriate exceptions.
    2. Other steps for "Create Map Place"

    UC004-E1: User is NOT logged-in or session expired

    Steps:

    1. Show appropriate message to the user for log-in or session expired and provide log-in option (button).
    2. terminate use case. [user can choose to go back to map view or go to log-in screen]

    UC004-E2: Location Access has NOT been authorized.

    Steps:

    1. Show appropriate message to the user for setting location access and provide setting options (button) in the configuration.
    2. terminate use case. [user can choose to go back to map view or go to settings options]

    UC004: Create Place on Map (Without Preconditions)

    Steps:

    1. Check user is logged in and user session is active. If not, run UC001.
    2. Check if user has previously authorized Location Access. If not, show appropriate message and run UC002.
    3. Other steps for "Create Map Place"

    UC004 > UC001: User is NOT logged-in or session expired

    Steps:

    1. Show appropriate message to the user for log-in or session expired and run UC001
    2. User logs-in successfully, continue UC004 Step#2
    3. User is not logged in successfully, terminate the use case.

    UC004 > UC002: Location Access has NOT been authorized

    Steps:

    1. Show appropriate message to the user for location authorization and run UC002
    2. User authorized location success, continue UC004 Step#3
    3. User did not authorized location access, terminate the use case.

提交回复
热议问题