我们可以将数据访问层类声明为非静态类吗?如果是这样,是否会导致交易问题? [英] Can we declare data access layer class as non static class. If so will it leads to transactions problem?

查看:65
本文介绍了我们可以将数据访问层类声明为非静态类吗?如果是这样,是否会导致交易问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

由于将DAL(数据访问层)类声明为静态,我非常困惑.如果我将DAL(数据访问层)类声明为非静态类,将导致事务问题.

例如:我的应用程序DAL(数据访问层)类是非静态的.每当用户访问它时,它将创建该类的新实例.当两个用户同时访问表中的相同字段时.当任何用户的网络连接速度慢时,它是否会导致交易.

Hi All,

I''m very much confused for the reason of declaring DAL(Data Access Layer) Class as static. If i declare DAL(Data Access Layer) class as non static will it leads to transaction problem.

For Example: My application DAL(Data Access Layer) classes are in non static. Whenever users access that it will create new instance of that class. When two users accessing same field in table in same time. Will it leads to transaction when any user is in slow net connection.

推荐答案

问题不是用户,而是潜在的在同一应用程序中有两个实例.

即使您声明它是静态的,您也可以让两个用户从不同的PC访问同一数据库-这可能会导致事务问题,在设计任何系统时都必须牢记.静态或非静态不会对此造成影响.

静态只是防止程序看到两个不兼容的数据层版本.这不是必需的,并且可以防止使用某些模式(例如Factory模式).静态,单例或实例化-在很大程度上取决于个人喜好.
It''s not the users that are the problem - it''s the potential for having two instances within the same application.

Even if you declare it as static, you can have two users accessing the same database from different PCs - which could cause transaction problems and has to be kept in mind when designing any system. Static or non-static will not affect that.

Static just prevents there being two incompatible versions of the data layer as seen by the program. It''s not necessary, and can prevent some patterns (such as the Factory pattern) being used. Static, Singleton, or instanced - it is a matter of personal preference to a large degree.


这篇关于我们可以将数据访问层类声明为非静态类吗?如果是这样,是否会导致交易问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆