【发布时间】:2013-08-29 08:44:11
【问题描述】:
有时我必须在课堂上编写大代码,所以我所做的就是这样,
Class ABC //it's a web service class
{
Public void Method-1() //used "-" for easy to read
{
//DoSomething and get something from database
Method-2(pass parameters that i got from database);
}
Public void Method-2(parameters)
{
DoSomething again and get data from another database. and some other source
do some processing by calling web services (just as example)
Method-3(parameter);
}
Public void Method-3(parameters)
{
DoSomething again and get data from another database. and some other source
do some processing by calling web services (just as example)
Method-4(parameter);
}
// and it keeps going
}
另一种方式
Class ABC //it's a web service class
{
Public void Method-1() //used "-" for easy to read
{
Method-2();
Method-3();
Method-4();
// so on....
}
}
这是正确的做法吗?如果不是,那么最好的做法是什么?
编辑
@Sayse 我正在尝试从不同来源获取信息并尝试构建一个大的 XML 文件,这使我可以使用 4、5 个 foreach 循环从 sql 等获取数据。所以使用嵌套方法
【问题讨论】:
-
我猜你的问题的合适位置是codereview.stackexchange.com
-
Precious 1tj 可能是对的,但他们可能需要更多关于您正在尝试做什么的信息,即您可以从方法 2 等开始
-
作为旁注:您可以使用
_而不是-来获得相同的名称和数字分隔,但会产生合法的方法名称。 -
我将建议您的第二个选项。这更容易修改和测试(您可以测试单独的方法而无需自动调用其余方法)
标签: c# web-services .net-2.0