Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Methods 将方法数据返回到另一个方法是错误的吗?_Methods - Fatal编程技术网

Methods 将方法数据返回到另一个方法是错误的吗?

Methods 将方法数据返回到另一个方法是错误的吗?,methods,Methods,我想知道使用另一个方法的数据调用一个方法是否是一种不好的做法。在我看来,它应该是好的,因为它节省了一个额外的实例化。我正在使用静态数据进行自动化测试 我有一个类DefaultValues,它包含应该出现在我正在测试的屏幕上的默认值 public static Dictionary<string,string> GetBackOfficeDefaults() { return new Dictionary<string, string>{ {

我想知道使用另一个方法的数据调用一个方法是否是一种不好的做法。在我看来,它应该是好的,因为它节省了一个额外的实例化。我正在使用静态数据进行自动化测试

我有一个类DefaultValues,它包含应该出现在我正在测试的屏幕上的默认值

public static Dictionary<string,string> GetBackOfficeDefaults()
{
     return new Dictionary<string, string>{
           { "currency", Currency}, { "wholeNumber", WholeNumber}, { "number", Number},
           { "date", Date}, { "comboBox", ComboBox}, { "memo", Memo}, { "text",Text}
     };
}
所以,我应该创建一个新变量,然后传递它,还是简单地将一个方法作为参数调用就可以了。下面这条路安全吗

Dictionary<string, string> values = DefaultedValues.GetBackOfficeDefaults();
VerifyCustomFields.RequiredDefaultValues(values);
Dictionary values=DefaultedValues.GetBackOfficeDefaults();
验证CustomFields.RequiredDefaultValues(值);

提前感谢您的帮助。

我不知道您项目的结构,但请关注您的问题基本上使用一种方法来创建对象是一种称为Factory方法的设计模式,因此这是一种不错的做法,但我不知道您项目的整个结构,因此我无法告诉您它是否得到了很好的实施,但您可以登录此网站了解更多信息:

Dictionary<string, string> values = DefaultedValues.GetBackOfficeDefaults();
VerifyCustomFields.RequiredDefaultValues(values);