假設我們有一個ASPX/PHP文件作爲REST服務,只是在頁面加載時我們使用switch case來引導用戶到所需的函數並返回一些值。我的問題是,如果這個頁面的功能超過1000,這是否會影響性能和響應時間?ASPX/PHP頁面大小有很多開關情況會影響性能
示例代碼可能是這樣的:
protected void Page_Load(object sender, EventArgs e) {
try {
string ServiceOutput = "";
string Function = Request.Form["Function"];
switch (Function) {
case "GetPluginsInfo":
ServiceOutput = GetPluginsInfo();
break;
case "demo":
ServiceOutput = Request.Form["Message"];
break;
.
.
.
.
}
Response.Write(ServiceOutput);
}
catch (Exception Error) {
Response.Write(Error.Message);
}
}
我不會擔心性能,更關心可維護性和可讀性。 1000個案例?!這種切換不能以另一種更合乎邏輯的方式完成嗎? – deceze 2010-11-12 09:51:23
我知道它起初看起來很奇怪,但我需要將所有功能放在一個頁面中作爲項目需求。似乎KBoek有更好的代碼時尚提供... – 2010-11-12 10:21:06