2

I am building an application consisting of 3 components, each comprising a GUI part (views, controllers, presenters) and a domain part (use cases and entities). There is one common infrastructure component (database). With this I am trying to adhere to the clean architecture principles: dependencies towards the domain layer, and using dependency inversion to enable a flow of control indicated with the green arrow

There is a specific order in which the components are used (workflow). When a certain state is reached in a component (can be user initiated or after some work has been finished in the domain layer), the next component needs to be initialized and the GUI needs to move to the next view/page. Furthermore, each workflow step produces an output which serves as input for the next step, thereby setting the state of the next component (black dashed arrows from left to right). This data (ID: string, Matrix3D: 4x4 matrix) needs to be communicated across components.

Architecture

  • What (and why) is a good solution (i.e., in which layer) to implement workflow logic, i.e., (de)activating components and initiating the transition to a new “view/page”?

    • E.g. I could add yet another domain component superordinate to all other domain components which deactivates the current component, initializes the next component, and initiates a transition in the view component.

    • E.g. I could add yet another GUI component superordinate to all other GUI components initiates transition in the views. Once the view is initialized, it could initiate the initialization of the corresponding domain component.

  • What (and why) is a good solution to communicate data across components?

    • E.g., I could communicate the data via the infrastructure layer.
    • E.g., I could pass all data that needs to be exchanged between components to the GUI layer (eventhough not all of this data is required in the GUI) and manage data exchange there.
    • E.g., I could directly communicate in the domain layer (e.g., using a messaging system).

1 Answer 1

1

It sounds like you would need an overarching GUI component that represents the actual workflow and uses instances of those other components. Most UI frameworks would help you with such composition. Since you didn't tell us which framework you are using you'd have to figure that out using the frameworks docs.

Generally make sure you create a loose coupling between parent and children to ensure the subordinate components can be reused independently.

Also another thing you didn't ask for - In your diagram all components use the same DB block in the bottom. Its not clear what that means exactly, but make sure that each component has their own independent persistence, for example separate tables. Any need to communicate state from one component to the next should go through an API of the component owning the data and not through directly shared DB tables.

5
  • In the GUI I am using Qt with QML. Why do you think it is better to manage the workflow in the GUI and not on the domain layer level? Regarding the persistence, actually all of my components use the same persistence. I guess I should change that, however can you explain why it is better to communicate through an API instead of through the persistence?
    – user137589
    Nov 6, 2021 at 20:49
  • 1
    Shared DB tables are a tight coupling / dependency and you cannot evolve the components independently. When the table schema changes all components have to change. And without knowing your use case - I assume there may be workflow specific UI and domain level considerations? So probably good to represent it on both levels? Nov 7, 2021 at 0:55
  • 1
    Splitting up the persistence makes sense, thanks for the explanation. Regarding the workflow: There are scenarios where the user clicks a button which will directly initiate a transition in the view. This can be handled in the GUI. There are scenarios where the user clicks a button and depending on the state of the component (e.g. if some data, a 4x4 matrix resulting from an algorithm, is available), the UI must start a use case or transition to the next view. How would you handle the latter case? And would you handle both scenarios the same way for consistency reasons?
    – user137589
    Nov 7, 2021 at 7:32
  • A typical pattern for implementing navigation between different components is to introduce a navigator component that is purely UI and knows how to show/hide your widgets. It would also keep the navigation state, routes and provide an easy interface to direct using those routes. I am not too familiar with QT but there may be existing libraries having a navigator component maybe? Nov 9, 2021 at 18:54
  • Yes I think what you are referring to are stackviews, swipeviews,... which will load the appropriate pages when told so. Using these, i.e., implementing the workflow in the GUI, is a feasible solution. However, the "clean" place to put logic is, as I understood, the domain layer. I read about Application Events that get fired from within a use case in component A and trigger another use case in component B. Nevertheless, the GUI would need to be informed about the component change. Does this make sense? Did you refer to this when you wrote "so probably good to represent both levels"?
    – user137589
    Nov 10, 2021 at 6:48

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.