需要对OOP理念的建议 [英] Need advice on OOP philosophy

查看:127
本文介绍了需要对OOP理念的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让车轮转动在C#中的大型项目。我以前的经验是在Delphi中,在默认情况下,各种形式在其中(GASP)全局变量举行的一个应用的启动和形式引用创建。所以我想我的思想适应了100%的面向对象的环境,我的头在旋转只是一点点。

I'm trying to get the wheels turning on a large project in C#. My previous experience is in Delp where by default every form was created at applicaton startup and form references where held in (gasp) global variables. So I'm trying to adapt my thinking to a 100% object oriented environment, and my head is spinning just a little.

我的应用程序将有一个大的集合类大多数这种类只真正需要的一个实例。所以,我在想:静态类。我真的不知道为什么,但很多我在这里读的说,如果我的课将要举办的状态,这是我采取的意思是任何财产价值可言,我应该使用一个单结构,而不是。好的。但是,有些人在那里谁为逃避我,觉得单身是邪恶太的原因。

My app will have a large collection of classes Most of these classes will only really need one instance. So I was thinking: static classes. I'm not really sure why, but much of what I've read here says that if my class is going to hold a state, which I take to mean any property values at all, I should use a singleton structure instead. Okay. But there are people out there who for reasons that escape me, think that singletons are evil too.

这些类的没有一个是正在使用的危险的任何地方,除了在这个方案。因此,他们当然可以正常工作作为常规对象(单身VS或静态类)

None of these classes is in danger of being used anywhere except in this program. So they could certainly work fine as regular objects (vs singletons or static classes)

再有就是对象之间的互动问题。我很想创造一个全球一流的完全公开的静态属性引用许多类的单一实例。我也认为只是让他们的属性(静态或实例,不知道哪)的MainForm的的。然后,我有我的每个班要注意的是MainForm的所有者。随后的各种对象可以指对方为所有者。 Object1 ,所有者 Object2的等。

Then there's the issue of interaction between objects. I'm tempted to create a Global class full of public static properties referencing the single instances of many of these classes. I've also considered just making them properties (static or instance, not sure which) of the MainForm. Then I'd have each of my classes be aware of the MainForm as Owner. Then the various objects could refer to each other as Owner.Object1, Owner.Object2, etc.

我怕我跑了电子墨水的,或者至少是征税人热情地向的长期的耐心已经坚持了我这个。我希望我已清楚解释鸡犬不宁我的状态。我只是在寻找关于我的情况的最佳实践一些建议。所有输入欢迎和赞赏。

I fear I'm running out of electronic ink, or at least taxing the patience of anyone kind enough to have stuck with me this long. I hope I have clearly explained my state of utter confusion. I'm just looking for some advice on best practices in my situation. All input is welcome and appreciated.

在此先感谢,
大卫·詹宁斯

Thanks in advance, David Jennings

推荐答案

您可以尝试一下,看看是怎么回事。考虑NUnit的在你身边发展;如果你这样做,你会发现你的代码将保持足够的灵活性,这使得架构变化也不会太强硬。

You could try it and see how it goes. Consider developing with NUnit at your side; if you do you'll find that your code will stay flexible enough that making architectural changes won't be too tough.

我的选择是避免静态类和静态数据,但有时它只是使得短期内的问题意识。关于这一点,我的建议是要考虑什么实际拥有的各种形式。通常情况下人们似乎想使主窗体中的主要应用程序的事情,但也许有实际上是这种形式更好的所有者。

My preference is to avoid static classes and static data, but sometimes it just makes sense for the near term problem. On that, my advice is to consider what actually owns the various forms. Oftentimes it seems that people want to make the main form the "primary application thing," but maybe there actually is a better owner for that form.

Anyway-超越说起和沉思的可能是什么,我会建议只是去进取,尝试一些选项,看看他们做什么。不要害怕改变你的软件,你写后!

Anyway- beyond talking about and musing on what could be, I'd suggest just going ahead and trying some options out and see what they do. Don't be afraid to change your software after you write it!

这篇关于需要对OOP理念的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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