lundi 12 juillet 2021

Design pattern for CLI application that utilizes 2 families of objects that interact with each other

I'm developing an application that must communicate with platforms and projects that exist on those platforms. Platforms can consist of any number of projects. Projects can exist in any of the platforms, and represent a number of different types of projects. I am using a Factory pattern to construct the platforms and projects independently of each other:

My actual project types of

  • ProjectTypeA
  • ProjectTypeB
  • ProjectTypeC

I have a ProjectFactory that can create any of those project types.

I have a PlatformBuilder that can connect to and return an instance of the requested platform.

  • PlatformX
  • PlatformY
  • PlatformZ

Some of the actions I need to support include creating projects on the platforms. Copying files for a project from a platform. For this, I am using the Command Pattern to enable adding other actions later on.

For the actual commands, say create_project, this is a method on the Platform class, that is implemented in the concrete classes. It takes a Project object to get some basic information. Another command would be copy_output_files which would be a method on the Project class and take a platform object as a parameter. copy_output_files would need to query the platform to get the list of files.

The problem I have with this design it that the Project and Platform classes are now dependent on each other. I don't think this is a good. I've tried separating them and putting the actual steps in the Command class instead, so this makes it a Mediator pattern as well.

I'm trying to figure out if there is a better way of doing this.

Aucun commentaire:

Enregistrer un commentaire