本文介绍了Web架构:MVC,延迟初始化,数据传输对象,打开会话看来,是有共识的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么破绽你在下面看到设计的,(这将是您理想的架构建议)为典型的网络3层应用程序?

What flaws do you see in the following design, (and what would be your ideal architecture suggestion) for a typical web 3-tier application?

我目前的做法蓝图非常粗略(假设Java的,春天,休眠,JSP)

My current blueprint approach is very roughly this (assuming Java, Spring, Hibernate, JSP)

无状态,有可能包裹着一个只读的交易(以避免延迟初始化例外),仅通过该服务永久存储得到的实体,将它们传递到视图模型。开展对他们的业务逻辑(应BL在服务层只),传回的如果需要持久化服务层。

Stateless, potentially wrapped with a read only transaction (to avoid lazy init exceptions), get's entities from persistence storage via the service only, passes them to the view as the model. Conducts business logic on them (should the BL be in the service layer only?), passes back to the service layer for persistence if required.

赞成:对于只读交易换行 - 只有一个连接,对于同一个持久化实体没有多余的命中率,利用查询缓存更好,服务层不应该知道的请求参数,或要求初始化图形跨度,避免延迟初始化例外。

Pros: For read-only transaction wrapping - only one connection, no redundant hits for the same persistent entity, utilizes query cache better, service layer shouldn't "know" request parameters, or required init graph span, avoid lazy init exceptions.

缺点:只读事务的做法是有风险的,控制器是不理想的业务逻辑挂的地方......很难做到JUnits(你的输入是请求......)

Cons: The read-only transaction approach can be risky, controllers are not the ideal Business Logic hanging place... very hard to do JUnits (your input is a request...)

非事务性的(获得非懒的集合/成员将导致延迟初始化除外)

Non transactional (access to non lazy collections / members will result in a lazy init exception)

赞成


  • 视图作者不应该仅仅通过点符号影响应用程序的性能(例如因N + 1选择由于懒惰初始化的大集合。

  • The view author shouldn't affect by mere dot notation the performance of the application (e.g. cause N+1 selects due to lazy initializing a large collection.

此外,在断开连接的客户端(Flex或其他富客户端)延迟初始化远程要么不支持,或者只是不聪明的做法

Also in disconnected clients (Flex, or other Rich Clients) lazy initialization remotely is either non supported, or just not a smart thing to do

缺点:控制器/服务/ DAO必须prepare仔细实体右图的观点,并可能超调(性能)/下冲(延迟初始化异常)。的服务器端方法无数可引起杂波是有笛卡尔乘积的实体图形可以初始化排列的数目

Cons: the controller / service / DAO must prepare carefully the right graph of entities for the view, and may be overshooting (performance) / undershooting (lazy init exception). a myriad of server side methods can cause clutter as there is a Cartesian product to the number of permutations an entity graph can be initialized

使用持久对象按原样(无数据传输对象),状态保存在会话中。

Using the persistent objects as is, (no data transfer objects), state is saved in the session.

赞成:无需重新编写的POJO,现有实体的重用,会话状态比隐藏域更加安全的状态处理

Pros: no need to rewrite POJOs, reuse of existing entities, session state is more secure than hidden fields state handling.

缺点:坏断开框架,节省了陈旧的断开连接的对象的风险,锁定问题,压倒一切的其他数据的风险,需要乐观有时锁定

Cons: Bad for disconnected frameworks, risk of saving stale disconnected objects, risk of locking issues, overriding other's data, requires optimistic locking sometimes.

事务性的,不知道请求的范围,需要的是实际的持久化存储访问一个DAO层。这是在对BL应经典是,但它反复似乎对BL泄漏到控制器侧

Transactional, doesn't know the request scope, calls a DAO layer for actual persistence storage access. this is where the BL should classically be, but it seems the BL leaks to the controller side over and over.

包含原子持久性存储门面,懵懂的BL,或任何上下文

Contains atomic persistence storage facade, ignorant of the BL, or any context

你会在上面架构解决什么?

What would you fix in the above architecture?

你觉得(像我)这是一个相当普遍的做法(有一些细微的差别,比如在视图中打开的会话等)?或者是你第一次看到它,我做一些可怕的错误(或右)?

Do you think (like me) it is a quite common approach (with some minor differences, such as open session in view, etc)? Or is it the first time you see it and I'm doing something terribly wrong (or right)?

你怎么解决它在你的应用程序?你用你的实体的POJO也为您的模型和视图?或者你连线起来更简单的用户界面豆(所有完全初始化和安全)?

How do you solve it in your applications? Do you use your entity POJOs also for your model and view? or do you wire it up to simpler UI beans (all fully initialized and secure)?

这可能是一个主观的问题,但我敢肯定有明确的最佳实践设计patters该群集到一个,两个或三个最大一般的宗教。

This may be a subjective question, but I'm sure there are clear best practice design patters that cluster to one, two or three max general "religions".

推荐答案

总的来说,这似乎是一个很好的架构。如果你还没有读过,我建议企业应用架构的马丁·福勒模式,它描述了你的问题每一个主题。

Overall, it seems like a very good architecture. If you haven't already read it, I would recommend Martin Fowlers Patterns of Enterprise Application Architecture, which describe every subject in your question.

有没有多大的问题,你期望的性能是问题明确。根据我的经验,你认为他们是,你会发现他们越早,就越容易改变架构相匹配的性能瓶颈很少。

It is not clear from the question how large an issue you expect performance to be. In my experience, the performance bottlenecks are rarely where you think they are, and the sooner you find them, the easier it is to change the architecture to match.

您是正确的,可测试性是一个大问题。我用马丁·福勒 -pattern取得了一些成功。你也应该看一看监督控制器,来自同一站点。

You are right that testability is a major concern. I have used Martin Fowlers Passive View-pattern with some success. You should also take a look at Supervising Controller, from the same site.

这篇关于Web架构:MVC,延迟初始化,数据传输对象,打开会话看来,是有共识的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 10:58