我正在处理一个大型项目(对我来说),它将有许多类,需要可扩展,但我不确定如何规划我的程序以及类需要如何交互。

几个学期前我上了一门OOD课程,从中学到了很多东西;比如编写UML,并将需求文档转换为对象和类。我们也学过序列图但不知怎么的我错过了这节课,我没能记住它们。

在之前的项目中,我尝试使用从课程中学到的方法,但通常在我说“是的,这看起来像我想要的东西”时,我就会以代码结束,我不想再挖掘出新的功能。

我有一本Steve McConnell的《Code Complete》,我经常在这里和其他地方听到它的神奇之处。我读了关于设计的章节,似乎没有得到我想要的信息。我知道他说这不是一个固定的过程,它主要是基于启发式,但我似乎不能把他所有的信息都应用到我的项目中。

那么,在高级设计阶段(在开始编程之前),你要做些什么来确定你需要什么类(特别是那些不基于任何“现实世界对象”的类)以及它们如何相互交互?

我特别感兴趣的是你使用的方法是什么?你遵循什么样的过程,通常会产生一个良好的,干净的设计,将接近最终产品?


当前回答

我认为这里的答案应该是非常不同的,这取决于这个人在现实世界中的经验。

如果你只有一两年的工作经验,那么你必须明白这一点:你如何才能真正了解你的数据,并确切地了解你要做的事情?

是的,如果您已经在现实世界中工作了5年以上,那么您可以在许多软件开发过程模型或技术中选择任何一种。

但是光靠读书是得不到经验的。你应该在一个好的领导下的好团队中学习。

如果这是不可能的,那么你应该自己做。从编写一段可能非常糟糕的代码开始迭代,学习错误,丢弃所有错误,编写更好的代码等等。

您将学到很多关于代码库的知识。工具就是工具,它们不会教你任何东西。

其他回答

关于这一点,我所知道的最有趣的来源是Bertrand Meyer所著的《面向对象软件构建》第二版的D部分。

第四部分:面向对象的方法论:很好地应用该方法

19:关于方法论, 20:设计 模式:多面板交互 系统中, 21:传承案例研究: 交互系统中的“undo”,22: 如何找到课程,23: 课程设计原则,24:使用 继承好,25:有用 技巧,26分:风格感,27分: 面向对象分析,28:The 软件构建过程,29: 教学方法

有趣的是,第22章。如何在网上找到课程。

During my adventures of designing class structures, I’ve noticed that it’s very helpful to start with writing some pseudo-code. That means: I start with “writing” some general fragments of application’s code on a highest level, play with it, and discover the elements that are appearing – in fact, the elements that I – as a programmer – would like to use. It’s a very good starting point for designing general structure of modules and their interactions. After few iterations the whole structure starts to look more like a full system of classes. It’s a very flexible way to design parts of code. You can call it a programmer-oriented design.

恐怕人们不愿意听到这样的回答。无论如何,让我陈述我的观点。

OOP should be viewed as one of the paradigms, not as the superior paradigm. OOP is good for solving certain kind of problems, like developing a GUI library. It also fits into the style of software development usually followed by large software companies - an elite team of designers or architects lays down the software design in UML diagrams or some other similar medium and a less enlightened team of developers translate that design into source code. OOP offer little benefit if you are working alone or with a small team of highly talented programmers. Then, it is better to use a language that supports multiple paradigms and will help you to come up with a prototype fast. Python, Ruby, Lisp/Scheme etc are good choices. The prototype is your design. Then you improve on that. Use the paradigm that is best to solve the problem at hand. If needed, optimize hot spots with extensions written in C or some other systems language. By using one of these languages, you also get extensibility for free, not just at the programmer level but also at the user level. Languages like Lisp can dynamically generate and execute code, which means your users can extend the application by writing small code snippets, in the language that the software itself is coded! Or if you choose to write the program in C or C++, consider embedding an interpreter for a small language like Lua. Expose functionalities as plugins written in that language.

我认为,大多数时候OOP和OOD所创造的软件都是过度设计的受害者。

总之,我喜欢的写软件的方式是:

使用动态语言。 用这种语言编写设计(原型)。 如果有必要,使用C/ c++优化某些领域。 通过实现语言本身的解释器提供可扩展性。

最后一个特性使软件能够轻松地适应特定用户(包括我自己!)的需求。

只是引用http://www.fysh.org/~katie/computing/methodologies.txt

并且RUP的核心是一个您必须使用面向对象设计的小区域 人才……如果你没有它们,就像有一个方法论 100米跑。

“第一步:写关于快跑的故事。 第二步:画一张赛马场平面图。 第三步:去买紧身的莱卡短裤。 第四步:跑得非常、非常、非常快。 第五步:先跨线

第四步才是最难的。但如果你特别强调 在第1 2 3 5次,有可能没有人会注意到,然后你就可以 卖这个方法可能会赚很多钱 那些认为成为百米运动员有什么“秘密”的运动员

你问了一个很多作家用来写书的问题。有很多方法,你应该选择一个对你来说“最漂亮”的。 我可以推荐Eric Evans写的《Domain Driven Design》。另外,查看dddcommunity.org网站。