Topic: 分层的疑惑 |
Print this page |
1.分层的疑惑 | Copy to clipboard |
Posted by: guorui_wh Posted on: 2004-11-17 11:44 不知道各位大侠的项目是怎么分包(层次划分)的? 我随便想了一下,没有多少经验.如果用struts+spring+hibernate com.company.action --struts action com.company.form --form bean com.company.po.hibernatepo --hibernate po and mapping file ( hbm.xml ) com.company.vo --vo com.company.dao -- dao interface com.company.dao.hibernateimp --hibernate dao implements com.company.service --service interface com.company.service --service implements 问题: 1.dao层要作什么事情?如果只是作create,update,delete,findById,那么dao层有什么用处,和hibernate 的工作是不是重复?如果让他作更多的事情,比如:再一次信息发布(内容管理中的一个功能)中,他需要作很多事情, 是不是dao就应该提供一个publish(),如果是这样的话,dao的工作好像又过了,因为service好像就是作这个事 情的! 请问各位大侠的项目是怎么样来把握这个度的?能举个实例最好了 2.vo能够出现再那些层次中?hibernate 的po对象可以充当vo,但是如果自己写vo(怕再业务逻辑中这样:po.setName()之类的), 那么vo,vo应该的两个边界应该是:action和dao 但是,如果界面上显示列表,怎么办?用formbean[]么?(以前我是用vo[]) 欢迎给出批评和意见,不胜感激~~~ |
2.Re:分层的疑惑 [Re: guorui_wh] | Copy to clipboard |
Posted by: guorui_wh Posted on: 2004-11-17 18:09 没有人愿意回答么? |
3.Re:分层的疑惑 [Re: guorui_wh] | Copy to clipboard |
Posted by: floater Posted on: 2004-11-18 04:06 dao is the interface, hibernate is just one implementation, there might be other implementations, jdbc, or even non relational database implementation. dao is the interface that services should depend on, services should *not* depend on hibernate at all. I just hate those po and vo. use just o or interfaces at the service/business layer, then use these o in other layers, or implement interfaces in other layers, but don't leave them at the top level of the package. The top level should have just com.cp.services com.cp.web com.cp.dao |
4.Re:分层的疑惑 [Re: guorui_wh] | Copy to clipboard |
Posted by: sanshaoye Posted on: 2004-11-18 15:26 I read the jpetstore sample code in spring dist pack. There only have domain object, no po,vo etc.. I already read Matin Flower's book ,but I can't understand it clearly. for example, we store a field in database using 'code', e.g. '1123', but when I display it to use, must translate it to 'China', and I store the associate of '1123' and 'China' in database, what tie to do this translate? and how to do it? |
5.Re:分层的疑惑 [Re: guorui_wh] | Copy to clipboard |
Posted by: guorui_wh Posted on: 2004-11-18 17:05 我也读了jpetstore,他确实没有vo,他把po贯穿mvc所有layer, 但是这样有个很大的问题,比如某个字段不合适了(修改字段,比如:把出生日期改成出生年,月,日,当然这个比方不是太好,但是能说明问题),那么所有的layer都需要修改,这样就不太好了,3层耦合太紧了 我还看了wiring这个例子,他也是没有vo的,也是把po传到jsp上,这样是很简单,但是耦合很紧 |
6.Re:分层的疑惑 [Re: guorui_wh] | Copy to clipboard |
Posted by: lianghyan Posted on: 2004-11-18 17:13 代码表的问题我也遇到过! 一个方案是将代码表的数据从数据库表中提取出来,作为一个资源, 在bo层做匹配。 但是感觉比较笨,不知道还有没有比较好的方案 |
7.Re:分层的疑惑 [Re: lianghyan] | Copy to clipboard |
Posted by: sanshaoye Posted on: 2004-11-18 18:52 lianghyan wrote: I think that was a good idea, like a cache. But the real problem is the field of that po is 'code' or 'name'? I think it will be code, what is the opportunity to translate it?and how to? Domain Object is a good or bad design? or, how to use it right? floater hate po,vo, but in javaeye and jdon, I found the guys strongly recommend divide this, and what are you think about that? You say the guys can't use DAO correct, what aspect your point? |
8.Re:分层的疑惑 [Re: guorui_wh] | Copy to clipboard |
Posted by: floater Posted on: 2004-11-18 23:10 I can cite some topguns agreeing with me and saying po, vo are bad. But I don't that's the point here, I think a more convincing approach is to figure out why po and vo are bad, how they invented. po and vo are just field holders for particular layers, they will change if we ever make any changes to the business layer. So there is extra bag to carry around in the maintenance. Between layers, if we have to use a different implementation, it would be better to use interfaces to shield out this and leave that particular implementation to that particular layer. Superficially, there is less difference between po, vo and bo. I think the root cause of this is that people think presentation layer, business layer, and database layer are of equal weight. This is exponentially wrong. The business layer dictates the other two. The consequence of this is whenever possible, don't use po, vo, use just bo. If you have to, hide them. Most of the time when I saw people are talking about DAOs, they put too much info unrelated to business layer into the DAO interfaces, such as DataSource, sql string. This is not right from the business point of view. |
9.Re:分层的疑惑 [Re: guorui_wh] | Copy to clipboard |
Posted by: lianghyan Posted on: 2004-11-19 09:39 我觉得是po,vo还是bo,可以根据项目的复杂度决定。如果你发现你的po,vo,bo(domain object)之间是在一个应用上下文,比如在一个jvm或容器中,他们之间转换的操作就是不停进行属性拷贝的话,那就没有必要了!如果他们之间确实因为业务需要而进行属性的组合,分裂等操作,从维护的角度就可以划分出来。 不过我现在遇到的项目中,service层和DAO使用domain object基本可以满足需要。 |
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 |