Chinaunix首页 | 论坛 | 博客
  • 博客访问: 180747
  • 博文数量: 12
  • 博客积分: 3000
  • 博客等级: 中校
  • 技术积分: 240
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-04 15:43
文章分类

全部博文(12)

文章存档

2011年(1)

2009年(1)

2008年(10)

我的朋友

分类: 项目管理

2008-08-09 18:24:04

                                   对象建模不简单

                Something about Object Modeling

 

在面象对向软件开发过程中(Object-Oriented Programming),对象构成系统的构件块,而对象是一个类的实体化, 一个面向对象模型的建立不是一个简单的工作,必须充分考虑到以下部分:

l         需要创建和实体化何种对象类型,特别是attribute 和方法的确定,我们把这称之为表态模型(static model)

l         这些所建立对象如何协作才能满足需求, 我们将这种细节的对象协作称之为协态模型(dynamic model).

 

类的确定是关建  Class is A Key

对象建模的第一个任务就是决定需要哪些类来构建系统,这决不是一个看似那么简单的事情,如果你是一个很熟练的面向对象程序员,你也可能会发现这很大程度依赖于直觉,或是说根据长期的建模经验.那么新手岂不是没有出路了,这对新手来说的确需要长期的训练,我自已学习对象建模也没有很长时间,只是在大二不系统的看了一些相关书籍,很多都是在后业编程实践中自己摸索。不过最近,我有看到Jacquiet Barker Grant PalmerBeginning C# Object 一书中介绍了一种很不错的方法来实现类的确定。下面通过一个例子来简单介绍一下这种可以叫做是Serach and Collection的方法。

SRSStudent Registration System)是一个高校的学生课程注册系统,这是一个应该很多人都有接触过的系统,可能对于类的确定也很熟,但以下是介绍Serach and Collection方法,可能对于这样一个小系统有点小题大做。SRS其需求说明书如下:

We have been asked to develop an automated Student Registeration System(SRS) for the university. This system will enable student to register online for course each smester,as well as track their progress completion of their degree.

When a student first enrolls at the university,he/she use SRS to set forth a plan of study as to which course he/she plans on taking to satisfy a particular degree program, and choose a faculty advisor .The SRS will verify whether or not the proposed plan of study satisfies the requirement of the degree that the student is seeking.

Once a plan of study has been established,then,during the registeration priod preceding each semester students ara able to view the schedule of classes online ,and choose whicheve classes they wish to attenend, indacating the prefferred section(day of the week and time of the day)if the class is offered by than one professor .The SRS will verify whether or not the student has satisfied the nessary prerequisites for each requested course by referring to the student’s online transcript of course completed and grades received(the student may review his/her transcript online at any time)

Assuming that (A) the prerequisites for the requested course are satisfied,(B)the course meet s one of the student’s plan of requirements,and (C) there is room avaible in each of the class(es),the student is enrolled in the class(es).

If (A) and (B) are satisfied,but (C) is not ,the student is placed on a first-come,first-served wait list.If a class/section that he/she was previously waitlisted for becomes avaible(either because some other student has dropped the class or because the seating capacity for the classs has been increased),the student is automatically enrolled in the waitlisted class,and email message to that effect is sent to the student.It is his/her responsibility to drop the class if it is no longer desired;otherwise,he/she will be billed for the course.

Student may drop a class up to the end of the first week of the semester in which the class is being taught.

 Search and Colletion方法:

l         标记所有的名词或名词性短语(Highlighting Noum Phrases in the SRS Specification),如上图所示

l         修改所有复数形式为单数形式,去除所有得到名词性短语中的重复短语(如文中多次出现了studentsstudent,

l         去除对系统自身引用的名词性短语:SRS,Student Registeration System,system

l         不符合对象概念的短语:如completion, end ,progress ,responsibility, registeration period.当然有些可能还值得商榷,对于还需要探计的短语,可以再用一个表记录下来,以便后业需要时再取

l         对于University的引用也可去除,因为SRS本身就是在一所大学里工作,如果是我们要建立跨校的系统,不要把University作为独立对象来建模。

l         将可能同意的短语分类列出来:尽可能用较短的短语的形式,如degreedegree program好;有些尽管不完全同意,transcript应该包括了一个学生的grades,所以后都可摒弃,。

class, course,section,

waitlisted class, preferred section,requseted courses, classes that he/she was previously wailisted

grades ,transcript

degree,degree program

professor ,faculty advisor

plan of study

day of week,time of day ,room,schedule of classes,seating capacity semester

student

 

l         当确定类名的时候,应尽量避免选择会暗示对象间角色(role)的名词,所以我们选Professor而非faculty advisor

l         可以看到,我们有很多的课程的名词和短语,我们应该删掉那些暗含角色关系的短语,如waitlisted class, preferred section暗含了studentcourse的关系,requseted courses暗含了两个course之间的关系

l         但是,可以发现,course class/section是两个不同的抽象概念,所以两者都需要

等等,Serach and Collection看上去是一个比较繁琐的过程,但是对于一些新手在面临较大系统项目时,这不时为一种很好的建模方法,对于类的确定还需要更多的考虑,对于不同的系统所要考虑的方面也不尽相同,但是有些不是可以通用的:

l         考虑某个名词短语是否要作为类,可以部以下问题:

        能想出这个类的attribute吗?

        能想出这个类的对象所提供的服务吗?

l         对于两种类的关联性名词,一般也不用作类

为软件系统开发合适的抽象类型,可能是整个开发过程中最关键也是最困难的方面了。抽象是观察者眼为的拓展,存在无限多种可能,永远没有所谓的“最好”的模型,只有对于某种需求的“较好”或“正确”的模型。

 

阅读(835) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~