求教:在构建,接口层,和数据库访问层,在执行效率方面,怎么设计好?
我现在是把系统内所有的接口方法都写在一个文件里面。
namespace VCShop.Data{ using System; using System.Collections.Generic; using System.Data; using System.Runtime.InteropServices; using System.Web.UI.WebControls; using System.Xml; using VCShop.Entity; public interface IDataProvider { object AddCommendUserScore(string orderID, string username, string type, string content); int AddProductASk(ProductAsk ask); int AddProductReivewBadCount(string id); int AddProductReivewGoodCount(string id); int AddProductReview(ProductReview review); int AddProductShopCut(ProductShopCut scut); int AddUserScore(string username, string score, string type, string content); int BindCouponUser(string Number, string Username); int CalcelOrderByUser(string ordernum, string remark); int CancelGroupBuy(long id, string Username); int ChangeAdminPassword(string Uid, string Password); int ChangeOrderIDInsert(string orderid, string tablename); int ChangeOrderIDUpdate(string id, string orderid, string tablename); int ChangeOrderUsedScore(string OrderNumber, string UsedScore); int ChangeUserScore(string username, string score, string content); bool CheckFittingExits(string id, string guid, string prop, string fittingproductid); int CheckIdCombo(Page src); DataTable CheckIsBlackIP(string ip); string CheckIsLastClass(string categoryid); bool CheckNameExits(string tablename, string name, string value); string CheckOrderProductExist(string PropertysID, string IsChangeSale, string IsFitting, string ProductID, string IsScore, string OrderNumber); int CheckPriceCard(string ids);……………………………… }}
namespace VCShop.Data.MsSql{ public class DataProvider : IDataProvider { private string strFilePath = ""; private const string strRoot = "/BaseConfig/"; public virtual object AddCommendUserScore(string orderID, string username, string type, string content) { return DbHelper.ExecuteNonQuery(string.Format("AddCommendUserScore N'{0}', N'{1}', N'{2}', N'{3}'", new object[] { orderID, username, type, content })); } public virtual int AddProductASk(ProductAsk ask) { StringBuilder builder = new StringBuilder(); builder.Append(" INSERT INTO [Web_ProductAsk]").Append("([Type]").Append(",[ProductID]").Append(",[UserName]").Append(",[Content]").Append(",[Pleased]").Append(",[Displeased]").Append(")VALUES ").Append("(''").Append("," + ask.ProductID.ToString()).Append(",'" + ask.UserName + "'").Append(",'" + ask.Content + "'").Append(",0").Append(",0").Append(")"); return DbHelper.ExecuteNonQuery(builder.ToString()); }…………………… }}
好象故意不想让人看懂似的。
[解决办法]
最好是分开吧!放在一起执行效率应该没有问题.
但是影响代码的可读性以及维护难度.
[解决办法]
同意楼上的 分开 容易维护
[解决办法]
分层开发,易于维护,易于修改,易于扩充
[解决办法]
分层是为了以后的维护 ,, 如果要测试时间请参考
static void Main(string[] args) { int a; Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 100000000; i++) { a = 1234; a = a + 10 - a % 10; } sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); StringBuilder sb = new StringBuilder(); int b; for (int i = 0; i < 100000000; i++) { a = 1234; b = a / 10 * 10; if (b < a) { b += 10; } } sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); Console.Read(); }