模块的使用(或不) [英] The use of modules (or not)

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

问题描述

我读过.Net中的模块主要是为了向后兼容。

这是真的吗?


如果我有变量我想要接触所有课程(常规

班级,表格等),我觉得把它们放在一个模块中是很自然的,并且

将它们标记为公共。


或者是以不同的方式做到这一点?

问候/ Snedker

I''ve read that modules in .Net are mainly for backwards compability.
Is this true?

If I have variables I want to be exposed to all classes (regular
classes, forms etc), I''d find it natural to put these in a module and
dimension them Public.

Or is the proper way to do it differently?
Regards /Snedker

推荐答案



Morten Snedker写道:

Morten Snedker wrote:
我读过.Net中的模块主要是为了向后兼容。
这是真的吗?
<如果我有变量我希望暴露给所有类(常规类,表单等),我会发现将它们放在模块中并将它们标记为Public是很自然的。 br />
或者是以不同方式做到这一点的正确方法吗?
I''ve read that modules in .Net are mainly for backwards compability.
Is this true?

If I have variables I want to be exposed to all classes (regular
classes, forms etc), I''d find it natural to put these in a module and
dimension them Public.

Or is the proper way to do it differently?




一般情况下,尤其是面向对象编程,全球
$你描述的b $ b变量是frow

编程实践的评论员是什么(参见

< http://c2.com/cgi/wiki?GlobalVariablesAreBad>用于讨论

链接)。任何时候你想要创建一个全局变量,你都应该自己问:
:这个新的

变量是否属于''属于'真的没有已存在的对象?它不应该是一个共享成员吗?某些类的
代表你的应用程序的主要组件?


-

Larry Lard

回复团体请



In general, and especially in object-oriented programming, global
variables such as you describe are frowned upon by commentators on
programming practice (see
<http://c2.com/cgi/wiki?GlobalVariablesAreBad> for discussion with
links). Any time you want to create a global variable, you should ask
yourself: is there really no already-existing object that this new
variable rightly ''belongs'' to? Should it not rather be a Shared member
of some class that represents the ''main'' component of your application?

--
Larry Lard
Replies to group please


Morten,
Morten,

如果我有变量,我想要接触所有课程(常规课程,表格等),我会发现把它们放在一个模块中是很自然的,并且将它们标记为公共。

或者是以不同方式做到这一点的正确方法吗?

If I have variables I want to be exposed to all classes (regular
classes, forms etc), I''d find it natural to put these in a module and
dimension them Public.

Or is the proper way to do it differently?



我不会这样做。每次程序

超出构造范围时,每个对象都会被破坏。


该程序可以在每个级别上进行。甚至在if语句中。通过

在程序中尽可能保持最好的

内存管理,而当其他人时它也非常具有描述性

正在读回你的程序。 (没有什么比在任何地方创建的全球价值更糟糕了。)


您在程序中使用的大多数都是对象。我认为很少有理由将全球性的东西用于b
。 (尝试越来越多,以避免共享类。尝试几乎所有的
实例)。


通过实例查看此示例。


您已创建了一些数据集,并将其绑定到数据网格。使用设计器的
datagrid在你的表单上是全局的。


因此对数据集的引用是。


dim ds as DataSet = directcast(mydatagrid.datasource,DataSet)


您现在可以像使用全局一样使用数据集。


我希望这能给出一些想法


Cor


I would not do that. Every object is destructed every time that a procedure
goes out of scope in which it is constructed.

That procedure can be on every level. Even inside an if statement. By
keeping it as far much as possible at the procedure you have the nicest
memorymanagement, while it is as well very describtive when somebody else
is reading your programs back. (Nothing more worse than a value that is
globaly created on a whatever place).

Most what you use in your program are objects. I see seldom a reason to have
something global. (Try more and more as well to avoid shared classes. Try to
instance almost everything).

See by instance this sample.

You have somewhre created a dataset and binded that to a datagrid. That
datagrid using the designer is globaly on your form.

Therefore the reference to your dataset is.

dim ds as DataSet = directcast(mydatagrid.datasource,DataSet)

You can now use the dataset as if it was globaly created.

I hope that this gives some ideas

Cor


如果你真的想使用全局变量,谷歌可以使用单例模式。

绝对没有错误的全球在这种情况下的变量,因为它们被妥善管理,你可以保护实现足够的

来自变化。它们在许多情况下都是必不可少的(我在我目前使用的软件中将它们用于我的

缓存管理器) - 是的,你可以

定义你的单身人士用于全局访问的模块中的类。

" Morten Snedker" < morten_spammenot_ATdbconsult.dk>在消息中写道

新闻:1e ******************************** @ 4ax.com ...
If you really want to use globals, google for the singleton pattern. There
is absolutely nothing wrong with "global" variables in this context, as long
as they are managed properly and you protect the implementation sufficiently
from changes. They are essential in many circumstances (I use them for my
"cache manager" in the software I am currently using) - and yes, you can
define your singleton class in a module for global access.
"Morten Snedker" <morten_spammenot_ATdbconsult.dk> wrote in message
news:1e********************************@4ax.com...
我读过.Net中的模块主要是为了向后兼容。
这是真的吗?

如果我有变量我想要接触到所有课程(常规课程,表格等),我会发现把它们放在一个模块中并将它们标记为公共是很自然的。

或者是以不同的方式做到这一点?

问候/ Snedker
I''ve read that modules in .Net are mainly for backwards compability.
Is this true?

If I have variables I want to be exposed to all classes (regular
classes, forms etc), I''d find it natural to put these in a module and
dimension them Public.

Or is the proper way to do it differently?
Regards /Snedker



这篇关于模块的使用(或不)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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