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

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

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

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

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

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


当前回答

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

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

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

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

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

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

其他回答

我用于初始设计(得到类图)的步骤是:

Requirements gathering. Talk to the client and factor out the use cases to define what functionality the software should have. Compose a narrative of the individual use cases. Go through the narrative and highlight nouns (person, place, thing), as candidate classes and verbs (actions), as methods / behaviors. Discard duplicate nouns and factor out common functionality. Create a class diagram. If you're a Java developer, NetBeans 6.7 from Sun has a UML module that allows for diagramming as well as round-trip engineering and it's FREE. Eclipse (an open source Java IDE), also has a modeling framework, but I have no experience with it. You may also want to try out ArgoUML, an open source tool. Apply OOD principles to organize your classes (factor out common functionality, build hierarchies, etc.)

当我有机会时,我通常会使用我所谓的“三次迭代规则”。

In the first iteration (or startup), I devise the general layout of the application according to the model objects, the algorithms, and the expected (really expected, not maybe expected) future directions. I don't write design documents, but if I have to coordinate multiple people, a rough sketch of the procedure is of course needed, together with an analysis of dependencies and guesstimate of the time needed. Try to keep this phase to a minimum if, like me, you prefer a more agile method. There are cases where a strong design phase is needed, in particular when everything is known and true about the logic of your program, and if you plan to have a lot of interactions between features in your code. In this case, use cases or user stories provide are a good high level idea, in particular for GUI apps. For command line apps, and in particular libraries, try to write "program stories" in which you code against the library you have to develop and check how it looks. These programs will become functional tests of your library when completed.

After this first iteration, you will have a better understanding on how things interact, got out the details and the rough spots, solved issues with a slapped duct tape patch. You are ready to make use of this experience to improve, clean, polish, divide what was too large, coalesce what was too fragmented, define and use design patterns, analyze performance bottlenecks and nontrivial security issues. In general, all these changes will have a huge impact on the unit tests you wrote, but not on the functional tests.

当您完成第二次迭代时,您将拥有一个经过良好测试、良好记录和良好设计的小珍宝。现在您已经有了进行第三次迭代(扩展)的经验和代码。您将添加新的特性和用例来改进应用程序。你会发现一些粗糙的地方,最终你会进入与第二次类似的第四次迭代。清洗并重复。

这是我软件设计的一般方法。它类似于螺旋设计,具有简短的,三个月的迭代,以及敏捷开发的元素,允许您了解问题并了解您的软件及其应用领域。当然,这是一个可伸缩性的问题,所以如果应用程序非常大,涉及到数百名开发人员,事情就会比这复杂一些,但最终我想想法总是一样的,分门别类。

总结一下:

在第一次迭代中,您将体验并学习它 在迭代2中,您将清理产品并为未来做好准备 在迭代3中,您添加了新特性并了解了更多 转到2

我使用测试驱动设计(TDD)。首先编写测试实际上有助于引导您获得干净和正确的设计。见http://en.wikipedia.org/wiki/Test-driven_development。

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

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

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

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

如果你对你要从事的项目有专业知识,比如银行业。你可以很容易地构建你的对象,而且你知道每隔一天就会有这些增强。

如果你没有这方面的专业知识,那就和有这方面专业知识的人合作,把这些想法转化为技术细节。

如果你对如何组织你的项目设计感到困惑。盲目地遵循“实用的程序员”这本书。我以前也遇到过同样的情况,试着读那本书的一章。它会改变你作为软件开发人员的思维方式。