Skip to main content
 首页 » 编程设计

c#之C# 中的类设计之DAL

2024年02月23日15飞鱼

我遇到了一个完全由静态方法组成的数据访问层类。此类由 Web 应用程序使用

例如

public class DataAccessLayer 
{ 
Public static PersonDetails GetDetails(int iPersonID); 
{ 
//implementation 
} 
Public static bool SaveDetails(PersonDetails objPerson); 
{ 
//implementation 
} 
 
} 

写这样的代码是不是一个好习惯。我可以理解使用静态方法时性能会稍微好一些,但是当多个用户调用Page时会不会导致并发错误?

请您参考如下方法:

Is it a good practice to write such code.

在我的团队中开火,破坏了很多好的做法,我建议任何写出类似东西的人都去给我的竞争对手并为他们工作。

I can understand the fact that the performance will be slightly better when I use static methods.

比如 0.000000000000000000001%?

but will this cause any concurrency errors when multiple users call the Page?

取决于方法的编写方式。但是,它违反了面向对象,使依赖注入(inject)变得更加困难,难以在事务协调器下使用适当的事务分界,并且难以对事物进行单元测试/模拟。