反模式的名称是什么?在这种模式中,方法采用一个通用的上帝对象,该对象具有方法可能需要的所有属性,而不是显式声明该方法需要什么?
例如:
public class BaseRequest
{
User user;
Car car;
CustomerRecords customerRecords;
Folder folder;
// ... etc for 10 - 20 other unrelated parameters
}
public void doSomething(BaseRequest request)
{
User user = request.getUser();
// do stuff with user, ignore all other attributes of request
}
代替
public void doSomething(User user)
{
// do stuff with user, since it's nice and clear what we want
}
注意 - 我指的不是 BaseRequest
违反的单一职责原则。相反,我正在寻找反模式的名称,其中方法签名在其依赖项上“撒谎”。
此外,是否有任何优秀的博客文章可以简洁地解释这种模式的邪恶之处,我可以向其他人指出?
最佳答案
关于oop - 这个反模式的名字是什么?方法签名是个骗子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5492687/