Best practice - HashMap instead of parameter list, good idea?

Hi Stackoverflow Community,

I am working on some code where a list of optional criteria criteria is presented to my Tao. The method signature contains a list of +/- 10 parameters that I really don't like and you want to reformat. Plus, I would like to avoid refactoring all method signatures from different layers just because I add / remove criteria

List searchParams(String name, Long countryCode, ...){
...
}

will become

List searchParams(HashMap<String,Object> map) {
    BeanUtils.populate(this,map);
    ...
}

Am I a little worried that this is due to bad practice, because I give up control of what is being transmitted on the card to give me such flexibility? So my question is, am I right on the right track?

+3
source share
4 answers

, Params . :

  • Map, /, ..
  • ( , ).
  • .
+8

/ , , HashMap . , , , , , .

+2

, . ,

public Person {
    private String name;
    private String countryCode;
}

, , HashMap .

+2

, , - factory, . .

, , DriverManager.getConnection: Connection, Properties . , DriverManager , .

: , .

+1

All Articles