java - Solutions for "too many parameters" warning -


in of methods, there too many parameters , hard maintain , read source code. , worried question "are passing appropriate values in appropriate order?"

i using checkstyle eclipse plugin , gives me warning more 7 parameters.

i not sure may coding standard , don't care it. when passing many parameters through view, service or dao, have noticed hard read , hard modify @ later times.

so, trying pass these parameters with...

  1. a number of objects or beans. give me problems because parameters wouldn't guarantee (not sure whether present or not).

  2. hashmap type parameters. may force me check validations , try match keys method-call sides.

above 2 approaches may lose compile-time errors checking. there suggestions reduce parameter counts?

there techniques reduce # of parameters;

  1. use minimized methods (break method multiple methods, each require subset of parameters)
  2. use utility classes (helper classes) hold group of parameters (typically static member classes)
  3. adapt builder pattern object construction method invocation.
  4. try reduce data flow between separate packages better architectural design.

refer standard java book;

  • java: how program
  • head first java
  • effective java

also try learn design patterns it'll extremely useful best coding practices.

  • head first design patterns

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -