【发布时间】:2011-12-07 01:54:09
【问题描述】:
一般来说,调用者应该保证将格式正确的数据传递给被调用的方法(因此被调用的方法假定数据始终有效)还是被调用的 strong> 应该进行数据验证的方法?每种方法的优缺点是什么?
this.data = user.input;
// Caller check data
if (!this.data) throw new Exception("Data cannot be null.");
obj.consume(this.data);
public void consume(data)
{
// Called check data
if (!data) throw new Exception("data cannot be null.");
}
【问题讨论】:
标签: design-patterns programming-languages methods call