论坛首页 Java企业应用论坛

讨论:多层架构中是不是绝对不能把PO传递到表现层?

浏览 126676 次
该帖已经被评为精华帖
作者 正文
   发表时间:2004-06-03  
凤舞凰扬 写道
pufan,如果MVC叫做系统架构,倒的晕的不该是你,该是我了,我无话可说。你好好看看MVC 的书,好好理清楚它的来源吧。

MVC就不是系统架构了?基本上当前所有的多层应用,不管你3层也好n层也罢,基础都是MVC,准确来说是MVC2。你说MVC不是架构,难道你做的系统中没有view没有contrl没有model?

凤舞凰扬 写道
(它最早出现于smalltalk,比较成熟地运用于java的swing,一直到后来b/s的广泛应用,才将这样的思维或者说模式移植到web应用中。smalltalk是架构么?swing是架构么?)

你看看你的思维逻辑:
mvc起源于smalltalk,因为samlltalk是编程语言所以smalltalk肯定不是架构,所以起源于smalltalk的mvc也不是架构。

呵呵,其他我不多说了,只是建议思路清晰后在到论坛上发言,这是对网友的尊重也是对你自己的负责。
0 请登录后投票
   发表时间:2004-06-03  
在 Pattern-Oriented Software Architecture, Volume 1,MVC是第125页,属于交互系统的体系结构模式之一

我估计不少人把体系结构等同于分层和如何分层了。
0 请登录后投票
   发表时间:2004-06-03  
potian 写道
在 Pattern-Oriented Software Architecture, Volume 1,MVC是第125页,属于交互系统的体系结构模式之一

我估计不少人把体系结构等同于分层和如何分层了。

   pufan ,好好看看这句话,MVC属于交互系统的体系结构“模式”之一,MVC可以运用在任何用户界面的交互系统,它是一种思维,也是一种模式(思维、模式是什么?是解决问题的一套固定的方法)。但它不叫架构!(很明显这两个是完全不同的概念啊?为什么就那么执拗那?)只能说我们的基于web的体系架构基本上都是应用该模式(你不用该模式,一样可以构造web架构)。这是两个概念,两个顺序,哪个先,哪个后,难道还不清楚么?
   potian说得好,很多人就把体系结构(它是架构的组成部分)等同于分层了,以为分成了:表示层+业务层+持久层,每个层用上比较好的框架就叫做架构了,是不是那?说是也是,但它只是架构的一个最基本的表现,甚至可以说是一个很肤浅的表现。
   说到这里了,其实更多的思考应该留给其他的朋友,像Quake Wang、potian我们各持己见,也不是谁能说服谁,各有各的立场和思考,其实最终目的也就一个,找到一个更加好的方法去构建更好的系统,愿是殊途同归吧。同样,这个论坛也给了我们这样的空间,这样的讨论激烈不过也还愉快(当中也许与某些朋友有些小摩擦,无心的,不要往心里去)。为了这个主题,我是发了蛮多帖子,也够累了,呵呵,最后,引用Quake Wang常挂的一句话“open your mind”,同样,“open us mind”!静一静,实践中去体味吧~~~~~~
   各位,彼此挂牌,休战,哈哈, ,怎么样?
0 请登录后投票
   发表时间:2004-06-03  
为啥有人就是宁愿抠字眼也死不认错呢?
真奇怪....
其实虚心求教是一种美德。三人行必有我师。
0 请登录后投票
   发表时间:2004-06-03  
总的来说还是精华嘛。。。
列入精华了。
0 请登录后投票
   发表时间:2004-06-03  
这两天比较忙,所以只是上来看,没有发言。其实我发起这个讨论的初衷就是提倡凡事都不要报绝对的态度,具体问题具体分析,而不是拘泥于概念,为XX而XX。事实上,传与不传都有自己的道理,归根结底,还是只能回到具体问题具体分析这句话上。但是,它只是一种策略,和分层的本质并不冲突,这点不可不说明。

下面是我摘录的两位Hibernate Team开发者的话,希望能对大家有所启迪。

michael from Hibernate Team 写道

 
I very much agree with dirkschmidts point, I really think DTOs are an evil thing. Basically this is all the way back to the structs of the C age. I really think both view and application logic should operate on the same domain model. If you need to restrict client access somehow use interfaces, and let the view work on the interfaces only, or use delegation/subclassing.

IMHO if you can't do something.getXXX() anymore in a view/client, you are seriously fucked Of course this gets you some other problems like object graph partitioning, to not load the whole object graph. I think Hibernates lazy loading features do a great job here allready on the server side, but it gets really nasty if you have rich-client applications where lazy loading carries a potentially large overhead.

I kind of like the idea behind Entity Beans remoting, if that would not make them totally unusable because of network overhead.

So IMHO, you should really try to reduce additional layers as much as possible, keep one domain model and try to use this domain model from the view, too. There is much to much overengineering around, promoting things like DTOs/DAOs and all that stuff in the name of the magical "decoupling", which will not be of use in most cases anyways. I allways try to stick with the YAGNI principle.

Just my two cents


steve from Hibernate Team 写道

 
A couple of thoughts. I have been giving this a lot of thought over the past 3 months for a proposal I am making to my bosses regarding a change in our application architecture. We currently have this pretty typically service layer setup where the service layer mediates between the UI and the domain model using DTOs as the exchange mechanism.

Are DTOs evil? I kind of go back and forth on this. In gerneral, no I don't think DTOs are evil. I think the amount of my time they waste is evil, but that is where something like CarrierWave comes into play by helping to manage not only the generation of the DTOs, but also the marshalling between DTO and domain entity.

I think it really comes down to the type of application architecture and topology you use. In a fully-colocated servlet-based or fat-client stack, DTOs probably don't make that much sense. Just open the Hibernate session and manipulate your entities at will. But what if you need to split that servlet-based stack into vertical partitioning for network security or clustering reasons? Now how do I manage this? I can't simply "Open Session in View" anymore... So I use Hibernate's disconnected object support.

But consider a product built using Hibernate that exposes an API in this fashion, that you as a developer need to interact with. So you retreive an object and then attempt to access one of it's properties (which happens to be lazy loaded). Boom, lazy init exception. "But the API says that object has that property..." Yes, I know, you could just simply initialize that lazy property prior to sending it outside of the persistence-context; but where does it stop? How deep should I init? Disconnected object support is great in all kinds of scenarios, but it certainly isn't a catch all.

I just don't think there is a hard-and-fast rule here that says you should never be using DTOs; and especially on the argument that they're not true object because they only represent data. Pure data representations are uber-useful for all kinds of things. To me, you're fooling yourself if you think you need a domain entity with all its domain logic intact to populate an html <select> list (if your using JSF or Tapestry or WebOGNL, then thats a different story).


最后说一句,Open your mind是常挂在我嘴边的话,不是Quake。Open us mind,我也欣然接受,虽然略略有些欠通。:)
0 请登录后投票
   发表时间:2004-06-04  
哈哈,我又弄错对象了,xanada,不好意思,只是对你的口头禅印象蛮深,张冠李戴了。
    等我项目做完,写篇《架构、框架与模式》,再和大家好好讨论讨论
0 请登录后投票
   发表时间:2004-06-04  
难得老皇同志你抽空写这么多文字去辩论MVC是架构还是模式。
0 请登录后投票
   发表时间:2004-06-04  
mikeho 写道
难得老皇同志你抽空写这么多文字去辩论MVC是架构还是模式。


我的原话是:
引用
多层架构有那么神秘吗?其本质无非就是MVC。


结果老皇同志非要论证MVC是架构还是模式,真是让人哭笑不得。 
0 请登录后投票
   发表时间:2004-06-04  
引用
结果老皇同志非要论证MVC是架构还是模式,真是让人哭笑不得。


In fact, many oo gurus call mvc an architecture pattern ;-). It's ususally be looked as a web presentation pattern.  As I think about MVC I see two principal separations:separating the presentation from the model and separating the controller from the view.
Of these, the sparation of presentation from model is one of the most fundamental heuristics of good software design. But this saparation is mainly concern about the domain logic not the domain info. So as in hibernate, po is all pojos, it isn't really a bad smell to return pojos to the presentation tier.

DTOs sometime is useful when we are working with a remote interface, such as Remote Facade,each call to it is expensive. As a result we need to reduce the number of calls,and that means that you need to transfer more data with each call. One way to do this is to use lots of parameters. However, this is oftern awkward to program, it's often impossible with languages such as java that return only a single value. So DTOs appears.

We could find that DTOs don't avoid of using pojo to do presentation work for one can wrap several pojo in a DTO. To be honest, I always return pojos into my web pages and I don't feel it causes any problems, anyway, it reduce a lot of my work to copy properties form pojos to DTOs. And I never separate my web tier from my domain tier, I mean they are both on the same server, so DTO is somehow not as useful as in web-domain distributed situation.

I don't understand what FengWuHuangYang means by VO? Does it represent for value object or visulization object? If it is the latter,it is DTO.
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics