假设参数都是同一类型,关于方法的参数数量是否有经验法则?我只是想知道我应该在哪里画线以及我的替代方案是什么(即接口(interface)、数组等)。
最佳答案
Steve McConnell 在 Code Complete 中解决了这个问题,引用的研究表明,人们实际上一次无法处理超过七 block 信息,因此在可行的情况下,七 block 是常识性限制。
在那一节的最后一段(第二版第 178 页),他写道:
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.
关于c# - 限制每个方法的参数数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2965984/