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...
a number of objects or beans. give me problems because parameters wouldn't guarantee (not sure whether present or not).
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;
- use minimized methods (break method multiple methods, each require subset of parameters)
- use utility classes (helper classes) hold group of parameters (typically static member classes)
- adapt builder pattern object construction method invocation.
- 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
Post a Comment