使用静态属性的形式不好的做法,明知有表格的只有一个实例? [英] Is using a static property in a form bad practice knowing that there's only one instance of the form?

查看:140
本文介绍了使用静态属性的形式不好的做法,明知有表格的只有一个实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个复杂的形式,我有一个名为只读属性,决定了如果一切可编辑与否。到目前为止,我通过这个属性各子自定义控件以这种形式被构造,而在其他地方,我访问的形式本身获得的价值。

In a complex form, I have a property called Readonly that determines if everything is editable or not. So far, I'm passing this property to every sub custom control in this form by constructor, and in other places, I access the form itself to get the value.

但是,这是迅速成为太复杂了。结果
我想使这个属性的静态的形式明知有这种形式的应用程序只有一个实例。

But this is quickly becoming too complex.
I'm thinking of making this property Static in the form knowing that there's only one instance of this form in the application.

是否确定使用这个属性在这种情况下,静态的? ,或者它是一个不好的做法,甚至只有一种形式的实例

Is it OK to use this property as a static in this case? Or it's a bad practice even there's only one instance of the form.

推荐答案

只要问自己:这是否涉及到的表格的或形式的键入的。可以想像,如果有不止一种形式 - 将他们全部是只读/不是在同一时间? ?还是会为每形式

Simply ask yourself: does this relate to the form or to the type of form. Hypothetically, if there were more than one form - would they all be readonly/not at the same time? Or would it be per form?

然后:你有答案。我怀疑它应该是实例(非静态)。

Then: you have the answer. I suspect it should be instance (non-static).

这篇关于使用静态属性的形式不好的做法,明知有表格的只有一个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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