jeudi 19 mars 2020

Method design approach where method takes variable number of values for a parameter

I have method that can take a single file name or array/list of files, and does some processing on them as follows:

public void methodName(String file, int arg2) {
...
}

OR

public void methodName(String[] files, int arg2) {
...
}

Lets say there is equal likely chance it will take single or list of files. What is the best design approach to this situations given no other restrictions?

  1. Create method 1 and write wrapper around it to handle list of files
  2. Create method 2 and write wrapper to handle single file instance
  3. none of the above

What things should you consider now and for future maintainability?

Aucun commentaire:

Enregistrer un commentaire