lundi 24 juillet 2023

Clean Code Architecture with transitive gateways - best practice

I am trying to refactor my project to match the Clean Code Architecture by Robert C. Martin Clean Code Architecture.

What is the best practice to use multiple gateways which depend on another gateway. Since all the instantiation should be done in an outer layer or the same layer, how should gateways communicate with other gateways?

  • Shouldn't we use multiple gateways at all?
  • Should the External System instantiate all gateways, work with them and just pass the first one to the use case?
  • Should the main just instantiate the first gateway and pass it to the use case, so every other gateway is instantiated by the gateways itself?

This is an example from my code:

  • main function which belongs to the External System and is the starting point.
  • DashVisualizer which plots a Plotly Dash Application and therefore is also an External System
  • Bunch of STL files as a Repository, so it's also an External System
  • BuildJob class which is an Entity
  • Part class which is also an Entity

So far everything is straight forward. The following is my attempt to categorize the transitive gateways and use case.

  • I have an STLFilesFinder class which searches for every STL file in the repository and creates a Dictionary of them. I assume it's a gateway.
  • Then I have a PartLoader which takes that Dictionary from STLFilesFinder and converts it to Part Entities. I don't want the STLFilesFinder to do that because it has already too much code in the class. So This must be also a gateway.
  • Last but not least I have the BuildJobLoader which takes all the Part entities and creates a Build Job Entities. This is also a gateway. To be clear: a Build Job consist of multiple Parts.

The Main functions has the configurations and creates every instance of these gateways and passes the output to the next gateway. The result (a dictionary) and the DashVisualizer object is passed to the BuildJobVisualizer (use case).

Aucun commentaire:

Enregistrer un commentaire