Topic: 一个设计的问题 |
Print this page |
1.一个设计的问题 | Copy to clipboard |
Posted by: palatum Posted on: 2003-10-13 16:52 我最近一直有一个问题在困扰我,希望大家能帮助我。 问题: 一个业务单据的类设计。 一个业务单据一般都有表头部分,条目部分两个大块。我原来的设计是这样的:3个类 Item类:描述条目信息 Sheet类:描述表头信息,包含一个Item类的数组。 Manager类:管理Sheet类,包含一个Sheet类的数组,还有保存表单(同时保存表头和条目),查询表单,更新表单内容和状态等等有关报单的操作。 我觉得这样挺烦人的。尤其是Manager类,很庞杂。一直想简化,但是不知道如何简化,希望有人能给出建议。 |
2.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: neilyoung Posted on: 2003-10-13 18:52 参考一下COMPOSITE PATTERN 吧。 |
3.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: floater Posted on: 2003-10-14 08:48 1. The simplest way is to post your code here so we may get some ideas what goes long. 2. You may have a form class to contain your table/item and sheet/table header class and then your manager class just delegates some operations to those classes. 3. check how Swing handles tables, I have a post "JDBC revisited", there is some code there, you may take a look too. For example, you may seperate input, output, state maitaining operations into seperate classes and inherit/compose them together, depending on whether you want to expose the interfaces to users of these classes or not. |
4.Re:一个设计的问题 [Re: neilyoung] | Copy to clipboard |
Posted by: palatum Posted on: 2003-10-15 09:02 neilyoung wrote: 看了一下COMPOSITE PATTERN,感觉好象不能满足要求。 |
5.Re:一个设计的问题 [Re: floater] | Copy to clipboard |
Posted by: palatum Posted on: 2003-10-15 09:40 floater wrote: I am reading your article now. I posted the Class Diagram of my question. Because of some reasons, I can't post the source code here. I posted a diagram of my design. pls help me. Thanks |
6.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: jacob Posted on: 2003-10-15 10:43 问题是不是出在数据的持久化代码重复? |
7.Re:一个设计的问题 [Re: jacob] | Copy to clipboard |
Posted by: palatum Posted on: 2003-10-15 10:55 jacob wrote: “持久化”,能说的更具体点它指什么吗?我不太理解。 |
8.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: neilyoung Posted on: 2003-10-15 16:09 palatum wrote: 单纯的看设计或者代码都无法给出中肯和满意的答复,因为偶不是很了解/熟悉描述的业务--可能理解能力有限。总之系统有什麽(输入)和它将要干什麽(输出),这两样东西在你的问题描述里都不甚明了。所以建议或者指导都是建立在代码级别上的,太底层,个人认为实际意义不大。 最后这个问题确实朦胧,唯一清楚的就是你依旧很头痛和烦人。 |
9.Re:一个设计的问题 [Re: neilyoung] | Copy to clipboard |
Posted by: palatum Posted on: 2003-10-15 16:35 好吧,撇开我那个头疼的问题,简单化。说一个简单业务。 产品入库,需要一张入库单记录。入库单上有一些诸如单号、入库日期、制单人、制单日期等项目,然后还有就是一些产品信息。入库单的管理流程是制单->库管确认->库房记帐。 请用OO的思想设计,完成上面这个业务。 |
10.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: floater Posted on: 2003-10-16 00:10 1. Your chart is symmetic, so let's concentrate on the left side(without loss of generality,gosh I haven't used this phrase for 10 years, ). 2. The top and bottom classes are bases, so I could ignore them in business logic. Now we have 3 objects: Manager, sheet and item. So I don't find anything wrong with your structure. (well, remove the getSheetItems() from the manager, that doesn't sound good) I assume you are using db and DAO: ItemDAO(used by Sheet) and SheetDAO(used by Manager) Manger: addSheet(); updateSheet(); deleteSheet(); selectSheet(); getSheetList(); Sheet: addItem(), updateItem(), deleteItem(), selectItem() getItemList(); Item: I just finished a similar structure like this and my manager class has 230 lines of code and 14 action methods. |
11.Re:一个设计的问题 [Re: floater] | Copy to clipboard |
Posted by: palatum Posted on: 2003-10-16 08:47 floater wrote: Where did you put the DB contact source code, another class or just in Manager Class? |
12.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: floater Posted on: 2003-10-16 22:04 palatum wrote: No, Manager shouldn't have db code. It's a business object. Check the graph below. It would be better that SheetDAO is an interface, but if you don't like it, ignore it. (If you use interface, use factory method too). |
13.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: floater Posted on: 2003-10-16 22:06 Manager.addSheet(...) --> SheetDAO.insertSheet() --> call sql to db. |
14.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: Biubiu Posted on: 2003-10-17 08:10 你的这种设计方式比较常见,应该说没有什么问题。关键是有一个Persistce Mananger,这样你的Business Manager的code就不会那么长了。 当然有更好的设计方式,可以参考《Server-based Java Programming》中关于Business Layer的论述。 |
15.Re:一个设计的问题 [Re: Biubiu] | Copy to clipboard |
Posted by: palatum Posted on: 2003-10-17 08:56 Biubiu wrote: Persistce Manager?Faint, Biubiu made a mistake. It should be Persistence. 能解释一下Persisitence Manager做什么的吗?如果有类图就更好了。 |
16.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: Biubiu Posted on: 2003-10-17 18:25 palatum wrote: Persisitence manager is responsible for persistent business object into data storage, for example the RDBMS. It may use JDO or ORM tool to do this. And I use Hibernate. Here's my persistent manager, FYI.
|
17.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: palatum Posted on: 2003-10-17 18:57 Thanks Biubiu. But I think that to define PersistentManager class as an interface maybe better. What do you think about? |
18.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: Biubiu Posted on: 2003-10-17 22:26 palatum wrote: You're right. The code snippet is from one of my projects. It's not a framework after all. |
19.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: floater Posted on: 2003-10-17 23:26 Persistence Manager should be one level above DAO. Biubiu's code should be the DAO implementation. Persistence Manager should be the manager for DAOs. In the same fashion, if appropriate, we should have business managers too for different business logic. Always use DAO interfaces, because these are the gates between two layers(We have far less layers than components, so layers are more distinct and we use interfaces). |
20.Re:一个设计的问题 [Re: floater] | Copy to clipboard |
Posted by: Biubiu Posted on: 2003-10-18 09:23 floater wrote: You are right. But I think persistence manager is part of data access layer and it's on the top of (not on top of) data access layer, just like the business manager is on the top of business layer. |
21.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: floater Posted on: 2003-10-19 02:01 Yep, that's the gateway. |
22.Re:一个设计的问题 [Re: Biubiu] | Copy to clipboard |
Posted by: palatum Posted on: 2003-10-21 15:35 Biubiu wrote: 看了两遍,还是不太理解,能给些建议吗?最好是UML图,类与类之间关系画清楚就行了。 |
23.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: jacob Posted on: 2003-10-21 18:42 赫赫。。。大家都喜欢UML...看起来方便,不用动脑子。。 |
24.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: Biubiu Posted on: 2003-10-22 10:00 palatum wrote: 里面不是有个例子吗,连代码都有啊? |
25.Re:一个设计的问题 [Re: Biubiu] | Copy to clipboard |
Posted by: palatum Posted on: 2003-10-22 12:43 Biubiu wrote: 好吧,继续啃第三遍。 |
26.Re:一个设计的问题 [Re: palatum] | Copy to clipboard |
Posted by: floater Posted on: 2003-10-22 23:17 check this dbsystem.vsd (87.0k) |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |