Best Practice - HashMap instead of list of parameters, good idea ?
java, methods, parameters, signature
Solution
When I encounter situations like this, I tend to create a `Params` class, and pass that around. The benefits are that:
- unlike when using a `Map`, you can have meaningful getters/settings, proper validation etc;
- it's type-safe and self-describing (meaning it's easy to find out the available parameters and their types).
- you can add new parameters without having to refactor any intermediate layers.
Problem
Hi Stackoverflow community, I am working on some code where a list of optional criterias criterias is submitted to my dao. Method signature contains the list of +/- 10 parameters, which I really don't like and want to reformat. Plus I would like to avoid having to refactor all method signatures from different layers just because I add/remove a criteria ``` List searchParams(String name, Long countryCode, ...){ ... } ``` would become ``` List searchParams(HashMap<String,Object> map) { BeanUtils.populate(this,map); ... } ``` I am a bit worried that this happen to because kind of a bad practice, because I give up control of what is passed in the map to give me that flexibility ? So my question is if I am on the right path proceeding that way?