你如何设计面向对象的项目? [英] How do you design object oriented projects?

查看:35
本文介绍了你如何设计面向对象的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个大型项目(对我而言),该项目将有很多类并且需要可扩展,但我不确定如何规划我的程序以及类需要如何交互.

I'm working on a large project (for me) which will have many classes and will need to be extensible, but I'm not sure how to plan out my program and how the classes need to interact.

几个学期前我参加了 OOD 课程并从中学到了很多东西;比如编写 UML,将需求文档翻译成对象和类.我们也学习了序列图,但不知何故我错过了讲座或其他什么,他们并没有真正坚持下去.

I took an OOD course a few semesters back and learned a lot from it; like writing UML, and translating requirements documents into objects and classes. We learned sequence diagrams too but somehow I missed the lecture or something, they didn't really stick with me.

在以前的项目中,我尝试使用从课程中学到的方法,但通常最终得到的代码是,只要我能说是的,这看起来像我想到的",我就不想深入研究添加新功能.

With previous projects I've tried using methods I learned from the course but usually end up with code that as soon as I can say "yeah that looks something like what I had in mind" i have no desire to dig through the muck to add new features.

我有一份 Steve McConnell 的 Code Complete 副本,我不断地听到这里和其他地方的内容很棒.我阅读了有关设计的章节,但似乎没有提供我正在寻找的信息.我知道他说这不是一个简单的过程,它主要基于启发式,但我似乎无法获取他的所有信息并将其应用于我的项目.

I've got a copy of Steve McConnell's Code Complete which I continually hear is amazing, here and elsewhere. I read the chapter on design and didn't seem to come out with the information I'm looking for. I know he says that it's not a cut and dried process, that it's mostly based on heuristics, but I can't seem to take all his information and apply it to my projects.

那么您在高级设计阶段(开始编程之前)做了哪些事情来确定您需要哪些类(尤其是那些不基于任何现实世界对象"的类)以及它们将如何交互彼此?

特别是我对你使用的方法感兴趣?您通常遵循什么流程才能产生出与最终产品密切相关的良好、简洁的设计?

Specifically I'm interested in what are the methods you use? What is the process you follow that usually yeilds a good, clean design that will closely represent the final product?

推荐答案

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

The steps that I use for initial design (getting to a class diagram), are:

  1. 需求收集.与客户交谈并找出用例,以定义软件应具有的功能.

  1. Requirements gathering. Talk to the client and factor out the use cases to define what functionality the software should have.

撰写单个用例的叙述.

仔细阅读叙述并突出显示名词(人、地点、事物),作为候选类和动词(动作),作为方法/行为.

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.

创建类图.如果您是一名 Java 开发人员,Sun 的 NetBeans 6.7 有一个 UML 模块,可以进行图表绘制和往返工程,而且它是免费的.Eclipse(一个开源Java IDE),也有一个建模框架,但是我没有这方面的经验.您可能还想试用开源工具 ArgoUML.

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.

应用 OOD 原则来组织您的类(分解通用功能、构建层次结构等)

Apply OOD principles to organize your classes (factor out common functionality, build hierarchies, etc.)

这篇关于你如何设计面向对象的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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