面向对象语言的最佳实践和适当的类设计(C#) [英] Best practice and proper class design in object oriented language(C#)

查看:74
本文介绍了面向对象语言的最佳实践和适当的类设计(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



众多人都知道,经过几个月的训练,任何人都可以编写一份有效的应用程序,但不是每个人都能写出一个漂亮而强大的应用程序如此短暂的时间段,事实上,许多具有几年经验的程序员仍然无法进行最佳实践课程设计,并且不可原谅地,我是那些穷人中的一员。



我通读了这个链接: http://msdn.microsoft.com/en-us /library/ms229042.aspx ,但这只是理论,没有实际的例子,我真正需要的是一个可以证明这些指导方针或原则的例子。



我用谷歌搜索过互联网,但大多数帖子都只是理论。这里的某个人是否可以提供一个解决良好的面向对象类设计的示例,或者将我指向具有此类示例的正确位置(最好在c#中)。



非常感谢。

Dear All,

As many folks know that anyone can write a working application after a few months trainning, but not everyone can write a nice and robust application in such short time of period, and in fact many programmers who had a few years experience still can't perform a best practice class design, and unfornaturely, i am one of those poor people.

I read through this link: http://msdn.microsoft.com/en-us/library/ms229042.aspx, but it is just theory and no practical examples there, what I really need is a example that can demonstrate those guidelines or principles.

I had googled the internet, but most of the post there are just theory. Can someone in here supply an example that addresses the good object oriented class design or point me to the right place that has such examples (preferable in c#).

Many thanks.

推荐答案

正如我从你的问题中可以理解的那样,你可以通过一些设计模式:

1. http://www.dofactory.com/Patterns/Patterns.aspx [ ^ ]

2. http://sourcemaking.com/design_patterns [ ^ ]



这些链接也有一些很好的工作示例。



您还可以看一本好书描述了使用.net开发框架时的最佳指南:

http://www.google.co.in/#hl=烯&安培; q =框架+设计+准则+ PDF&安培; OQ =框架+设计+&安培;水溶液= 1&安培; AQI = G10&安培; AQL =安培; gs_sm = E&安培; gs_upl = 9792l12385l4l13504l17l15l0l2l2l0l296l2621l0.2.9l11l0&安培; BAV = on.2,或.r_gc.r_pw。& fp = 38944046eb5a1414& biw = 1440& bih = 781 [ ^ ]



希望这会有所帮助。

一切顺利。
As I can understand from your question, you can go through some desing patterns :
1. http://www.dofactory.com/Patterns/Patterns.aspx[^]
2. http://sourcemaking.com/design_patterns[^]

These links also have some good working examples.

You can also have a look at a good book that describes the best guidelines when you are developing a framework using .net :
http://www.google.co.in/#hl=en&q=framework+design+guidelines+pdf&oq=framework+design+&aq=1&aqi=g10&aql=&gs_sm=e&gs_upl=9792l12385l4l13504l17l15l0l2l2l0l296l2621l0.2.9l11l0&bav=on.2,or.r_gc.r_pw.&fp=38944046eb5a1414&biw=1440&bih=781[^]

Hope this helps.
All the best.


嗯,AFAIK,还有没有能够展示所有指导方针和原则的完美范例。您可以做的是搜索每个主题的示例。做大块的事情。与您查看大型应用程序相比,这种方式更容易注册,这通常是压倒性的。 CP中有很多文章,其中包含您可以使用的代码示例。尝试搜索您想要熟悉的主题的文章。
Well, AFAIK, there's no such thing as perfect example that can demonstrate all guidelines and principles. What you can probably do is search for examples per topic. Do it chunk by chunk. It gets registered easier this way, than when you are looking at a large application, which is usually overwhelming. There are plenty of articles here in CP that has code examples that you can play with. Try searching for the article of a topic you want to be familiar with.


我知道这是一个较旧的问题,但我在搜索时遇到了谷歌的最高回报之一面向对象设计(OOD)链接给其他人。我认为通过Google为其他任何人添加更多信息会很有用,虽然对于OP来说已经相当晚了。

为了正确地将OOD应用于代码,你真的需要理解良好设计原则背后的理论。一旦我阅读了这些原则,我就希望看到一个很好的具体例子来提高我的理解,因此下面的大部分链接都会有很好的例子。 SOLID是一个涵盖几个优秀的OOD原则的首字母缩略词。有关OOD和SOLID的基本入门此处 [< a href =http://www.codeproject.com/Articles/93369/How-I-explained-OOD-to-my-wifetarget =_ blanktitle =New Window> ^ ] 。简而言之,SOLID代表以下5个原则:

1. 单一责任校长 [ ^ ] - 一个班级应该只有一个,而且只有一个可以改变。

2. 打开/关闭原理 [ ^ ] - 您应该能够扩展类行为,而无需修改它。

3. Liskov替代原则 [<一个人=https://docs.google.com/a/cleancoder.com/file/d/0BwhCYaYDn8EgNzAzZjA5ZmItNjU3NS00MzQ5LTkwYjMtMDJhNDU5ZTM0MTlh/edit?hl=en&pli=1target =_ blanktitle =New Window> ^ ] - 派生类必须可替代其基类。

4. 界面隔离原则 [ ^ ] - 制作客户特定的细粒度接口。

5. 依赖性倒置原则 [ ^ ] - 取决于抽象,而不是结石。



我还建议阅读< a href =http://www.amazon.com/dp/0596007124/>头部优先设计模式 [ ^ ]书。



如需进一步阅读,有一个关于OOP的好系列其中 [ ^ ]在CodeProject上。
I know this is an older question, but I ran into it as one of the top returns on Google while searching for Object Oriented Design (OOD) links for someone else. I thought it would be useful to add some more info for anyone else who may find this via Google, although it is rather late for the OP.
In order to properly apply OOD to code you really need to understand the theory behind good design principles. Once I read such principles I like to see a good concrete example to improve my understanding so most of the links below will have good examples. An acronym that covers several good OOD principles is SOLID. There is a basic primer on OOD and SOLID here[^]. In short SOLID stands for the following 5 principles:
1. Single Responsibility Principal[^] - A class should have one, and only one, reason to change.
2. Open/closed principle[^] - You should be able to extend a classes behavior, without modifying it.
3. Liskov substitution principle[^] - Derived classes must be substitutable for their base classes.
4. Interface segregation principle[^] - Make fine grained interfaces that are client specific.
5. Dependency inversion principle[^] - Depend on abstractions, not on concretions.

I also recommend reading the Head First Design Patterns[^] book.

For further reading there is a good series on OOP here[^] on CodeProject.


这篇关于面向对象语言的最佳实践和适当的类设计(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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