要使用静态还是不要使用静态? [英] To use static or to not use static?

查看:83
本文介绍了要使用静态还是不要使用静态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.....这就是问题。


任何人,我有一个应用程序,只有少数人会使用。
使用。其中一项功能允许他们将

人员列表检索到数据网格中。我想制作这样做的方法

static。一旦数据被检索,它就会在本地进行数据通信。他们不会更新它。这种情况发生在另一个地方。


这些修复方法是否会导致任何问题?我

不需要实例。但是,该方法是静态的

会导致第二个人看到第一个人检索到的结果吗?我不想要任何跨越数据的b $ b。我知道实例会在每个用户之间建立一个

的墙。我只是不确定用户是否会通过静态方法分享

数据。


谢谢,

Brett

解决方案

应该不是问题。


" Brett Romero" <交流***** @ cygen.com>在消息中写道

news:11 ********************* @ f14g2000cwb.googlegro ups.com ...

....这就是问题。

任何人,我有一个应用程序,只有少数人会使用。其中一项功能允许他们将
人员列表检索到数据网格中。我想制作这样做的方法是静态的。一旦数据被检索,它就会在数据视图中进行本地通信。他们不会更新它。这种情况发生在另一个地方。

这些撤销方法是否会导致任何问题?我不需要实例。但是,该方法是静态的会导致第二人看到第一人的结果吗?我不希望任何数据交叉。我知道实例会在每个用户之间建立一个
墙。我只是不确定用户是否最终会通过静态方法分享数据。

谢谢,
Brett



确定。如何让每个用户或多或少拥有他们自己的特定retreival数据?b $ b实例数据呢?我总是把静态方法想象为

,将相同的结果发送给每一个。我猜想,如果数据库正在改变并且两个人在

不同时间调用静态方法,他们会得到不同的结果,因为结果

是动态的。这是有效的逻辑吗?


例如,U1检索数据。 U2将人员添加到数据库中。 U3

检索数据,结果集中的人数比U1多一个。可以

发生了什么?


上面与使用实例有何不同?


谢谢,

Brett


你几乎无法阻止并发问题,例如数据是否为
在某人已经检索到它之后添加。


我认为你混淆了两个问题。静态方法返回的数据

是在其运行的进程或应用程序域中自己的副本。

大概每个用户都有一个不同的应用程序实例。


你的Ux场景肯定会发生。这只是

数据库的本质。现在,你的目标是什么?您是否希望所有人在数据库中更改后更新数据?
?如果您在本地加载数据,那么连接到数据库的时间就不会超过
,所以在您的

应用程序刷新数据之前,更改不会受到影响。

布雷特罗梅罗 <交流***** @ cygen.com>在消息中写道

news:11 ********************** @ g44g2000cwa.googlegr oups.com ...

好的。比起每个用户是否或多或少都拥有自己特定的撤销数据?我一直认为静态方法会将相同的结果发送给每个人。我想如果数据库正在改变并且两个人在不同的时间调用静态方法,他们会得到不同的结果,因为结果是动态的。这是有效的逻辑吗?

例如,U1检索数据。 U2将人员添加到数据库中。 U3
撤回数据,结果集中的人数比U1多一个。那可能会发生吗?

上面的内容与使用实例有何不同?

谢谢,
Brett



.....that is the question.

Any who, I have an application that only a handful of people will being
using. One of the features allows them to retrieve of a listing of
people into a datagrid. I''d like to make the method that does this
static. Once the data is retreived it is munipulated locally in a
dataview. They won''t be updating it. That occurs in another place.

Would making these retreival methods static cause any problems? I
don''t have a need for instances. However, will the method being static
cause the 2nd person to see results retreived by the 1st person? I
don''t want any crossing over of data. I know instances will build a
wall between each user. I''m just not sure if users will end up sharing
data via the static method.

Thanks,
Brett

解决方案

Should not be a problem.

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...

....that is the question.

Any who, I have an application that only a handful of people will being
using. One of the features allows them to retrieve of a listing of
people into a datagrid. I''d like to make the method that does this
static. Once the data is retreived it is munipulated locally in a
dataview. They won''t be updating it. That occurs in another place.

Would making these retreival methods static cause any problems? I
don''t have a need for instances. However, will the method being static
cause the 2nd person to see results retreived by the 1st person? I
don''t want any crossing over of data. I know instances will build a
wall between each user. I''m just not sure if users will end up sharing
data via the static method.

Thanks,
Brett



Ok. How is it than that each user still more or less has their own
instance of data from their specific retreival? I always thought of
the static method as sending back the same results to every one. I
guess if the DB is changing and two people call the static method at
different times, they will get different results because the results
are dynamic. Is that valid logic?

For example, U1 retreives data. U2 adds a person to the DB. U3
retreives data and has one more person in the result set than U1. Can
that happen?

Than how is the above any different from using instances?

Thanks,
Brett


There is little you can do to prevent concurrency issues such as if data is
added after someone has already retrieved it.

I think you are confusing two issues. The data that a static method returns
is its own copy within the process or app domain that it is running in.
Presumably each user will have a different instance of your application.

Your scenario with Ux definitely can happen. That is simply the nature of
databases. Now, what is your goal? Do you want all people to see that data
updated when changed in the database? If you load data locally, it is no
longer connected to the database so changes will not be affected until your
app refreshes the data.
"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

Ok. How is it than that each user still more or less has their own
instance of data from their specific retreival? I always thought of
the static method as sending back the same results to every one. I
guess if the DB is changing and two people call the static method at
different times, they will get different results because the results
are dynamic. Is that valid logic?

For example, U1 retreives data. U2 adds a person to the DB. U3
retreives data and has one more person in the result set than U1. Can
that happen?

Than how is the above any different from using instances?

Thanks,
Brett



这篇关于要使用静态还是不要使用静态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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