mardi 26 octobre 2021

Design Pattern to handle configuration depending on concrete implementations

I have the following code structure:

  • an algorithm interface defines a method execute(some_data, configuration).
  • various algorithms implement the interface and the execute(some_data, configuration) method differently.

The client now can create a concrete algorithm. Afterwards he passes some_data as argument to the method execute. Moreover, the client has to pass a configuration object ...

My problem is the following:

The configuration object strongly depends on the concrete algorithm. How can I structure this? Obviously I can define an abstract configuration and extend the concrete configuration depending on the concrete algorithm. But then I have to check inside of the concrete execute(some_data, configuration) implementation if the configuration fits to the class. I do not really know how to handle this ...

Can you help me? Is this a typical problem with easy best practice solution?

Aucun commentaire:

Enregistrer un commentaire