c# - 限制每个方法的参数数量?

标签 c# design-patterns parameters

假设参数都是同一类型,关于方法的参数数量是否有经验法则?我只是想知道我应该在哪里画线以及我的替代方案是什么(即接口(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/

相关文章:

java - 创建编译时未知的类的实例

swift - 如何在swift中生成带有参数的QRCode图像?

javascript - 如何将参数传递给 struts 标记中的 javascript 函数?

c# - 如何在不向服务器提交 SQL 语句的情况下获取 SqlParameter 的字符串表示形式?

c# - .Net 中的内存泄漏

c# - Linq 查询未按预期运行

java - 适用的设计模式

c++ - 从基类指针访问派生类成员的设计替代方案

c# - 如何添加系统 "windows hook"以便在创建/激活窗口时收到通知?

c# - 无法连接到 MySql 数据库 - "SELECT command denied for user [...]"