开发者

Static method in Data Access Layer

I have used a lot of static methods in Data Access Layer (DAL) like:

public static DataTable GetClientNames()
{
    return CommonDAL.GetDataTable("....");
}

But I found out that some developers don't like the idea of sta开发者_如何学JAVAtic method inside DAL. I just need some reason to use or not use static methods inside DAL.

Thanks

Tony


From purists' point of view, this violates all kinds of best practices (like, dependency on implementation, tight coupling, opaque dependencies, etc.). I would've said this myself, but recently I tend to move towards simpler solutions without diving too much in "enterprizey" features and buzzwords. Therefore, if it's fine with you do write code like this, if this architecture allows for fast development and is testable and, most important, solves your business problem -- its's just fine.


If I had to pick one reason not to use static methods, that would be that it limits your ability to write unit tests against your code. For example creating mocks for your DAL will be more difficult because there is not an actual interface to code against, just a bunch of static methods. This further limits you if/when you decide to adopt frameworks that require interfaces to support things like IoC, dependency injection etc.


That's Unit of Work, just static, isn't it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜