Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Architecture & Framework  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:Spring&Hibernate框架的程序设计 [Re:linux_china]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2005-05-09 03:00 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
My two cents:

User 在这里仅是一个PO对象,而不是实际生活中的BO(Business Object)对象

Actually, the most current opinion is that User is not PO. User is either an business object from the business layer, or an interface to be exposed to the lower persisitance layer. Note that this User, if it's an interface, may not be the entire business object interface, may be just the relevent portion to persistance. Basically, we use interfaces to shield/expose only the relevent methods,etc.


这里有人提出UserDao接口,这是一个什么角色?UserDao在我的眼中,它就
是一个工具类,将相关的操作整合到一个Java 接口中,没有依据一定的OO 设计方法。

Actually, UserDao is subject to the User context, so we still follow OO in that context, e.g., you dont' want to do irrelevent ops to User. So this is really not a tool class, more of a business object itself. For example, if your business doesn't have update method, then your DAO shouldn't have that.

If I understand you correctly, you try to seperate the DAO class to two: User for User specific operations, and UserHome for "general, non db" operations. You are annoyed by the fact that too much info are binded to the DAO class. I think this is the most commonly-seen misconception in the chinese community, here, javaeye, and others. The key is that DAO is belonging to the business layer(Rod mentioned in his second book with one line, and I specifically drew a char in my ibatis and spring doc). This one single fact has a very huge implicaiton to quite a few things. Most of the arguments in the chinese java community are based on just the opposite of this concept. The DAO interface should not have anything specific to database or any specific implementation(I could use a simple file for storage too). The DAO should obey rules in the middle layer as well. In the pre Spring era, due the transaction processes, there should be another very thin sublayer(of the middle layer) setting between persistance layer and business layer. This is very annoying and creates confusion too(I personally think that this thin layer is one of the root causes for the confusion in our community(Another cause is just that DAO shouldn't have any implementation details, but more and more folks become aware of this now).

Therefore, since DAO should have only dependencies in the middle layer, your User class can be combined with the UserHome class, which has the same characteristics. In fact, whether to split it into several classes is up to the business logic. For example, we discussed a case in here when we have some kind of search spinning across several tables, or more general, search across several different directions(This means, no matter what implementation you use, it's likely to seperate these different concerns anyway).


floater edited on 2005-05-23 09:22

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code

话题树型展开
人气 标题 作者 字数 发贴时间
17202 Spring&Hibernate框架的程序设计 linux_china 115 2005-05-07 16:55
13855 Re:Spring&Hibernate框架的程序设计 steven_652 35 2005-05-07 20:31
14554 Re:Spring&Hibernate框架的程序设计 floater 2732 2005-05-09 03:00
13556 Re:Spring&Hibernate框架的程序设计 jigsaw 1225 2005-05-22 17:05
13527 Re:Spring&Hibernate框架的程序设计 jigsaw 489 2005-05-22 17:37
13415 Re:Spring&Hibernate框架的程序设计 floater 2074 2005-05-23 09:18
13595 Re:Spring&Hibernate框架的程序设计 linux_china 286 2005-05-23 19:17
13369 Re:Spring&Hibernate框架的程序设计 jigsaw 318 2005-05-23 16:22
13563 Re:Spring&Hibernate框架的程序设计 floater 431 2005-05-23 21:47
16076 Re:Spring&Hibernate框架的程序设计 ben_nb 28 2005-06-15 12:21

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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