vendredi 12 mai 2017

Java classes with 'dynamic' number of methods?

let’s say that we have a class to which occasionally are added new checks and you end with something like describe below:

class CheckList{
  check1(){
   //do something
  }
  check1(){
   //do something
  }
  //...
  checkN(){
   //do something
  }
}

and you want to call all the checks in a straightforward way

I have considered the following options:

  1. use reflexion to get the methods, iterate and executing them
  2. use a list containing the check names, iterate and execute them
  3. use annotations to load, populate a map and go to 2

what I want to avoid is the need modify other classes each time that a new check is added.

is there a design pattern/recipe known to achieve such thing?

Aucun commentaire:

Enregistrer un commentaire