Limit number of parameters per method?

前端 未结 5 918
离开以前
离开以前 2021-02-19 07:57

Assuming the parameters are all the same type, is there a rule of thumb in regards to the number of parameters for a method? Im just wondering where I should draw the line and

5条回答
  •  臣服心动
    2021-02-19 08:23

    Steve McConnell addresses this in Code Complete, citing research that suggests people can't really handle more than seven chunks of information at a time, making seven a common-sense limit wherever it's practical.

    In the concluding paragraph of that section (page 178 in the second edition), he writes:

    If you find yourself consistently passing more than a few arguments, the coupling among your routines is too tight ... If you are passing the same data to many different routines, group the routines into a class and treat the frequently used data as class data.

提交回复
热议问题