samedi 15 avril 2017

Java best design for an object that can be different, but do the same

Basically I need to have a flexible design to process. Im thinking of something like this:

  • Have an Interface DataProcessor and then have concrete classes of different types like CSVDataProcessor,FTPDataProcessor,CloudDataProcessor.
  • All DataProcessor classes will implement a method process() defined on DataProcessor Interface

My question is:

What should be the best design to do it, if each concrete class needs different parameters to execute the process() method. For example, FTPDataProcessor will need parameters like the file, the host, the port - CSVDataProcessor will need the file location, and schema - CloudDataProcessor will need the endpoint service, user, password??

My first thoughts are, to use the constructor to pass the specific requirements to each concrete class, but what if there are a lot of parameters that are needed?

In the future, more DataProcessor concrete implementations will be added, and that is why I would like to have a very flexible design to implement it since the beginning.

Aucun commentaire:

Enregistrer un commentaire