简体   繁体   English

Java EE 6设计模式

[英]Java EE 6 Design Patterns

I would like to know about the design patterns that can be applied in Java EE 6 implementation. 我想知道可以在Java EE 6实现中应用的设计模式。

  • MVC. MVC。
  • GOF. GOF。
  • DAO DAO
  • Persistent relational mapping 持久关系映射
  • Pooling
  • CEC CEC
  • Entity control boundary (ECB) 实体控制边界(ECB)
  • and many others 和许多其他人

Do JPA eliminate the use of DAO? JPA是否取消了DAO的使用?
Please provide other patterns that can be learned. 请提供可以学习的其他模式。

There is a good reference here: http://martinfowler.com/eaaCatalog/ 这里有一个很好的参考: http//martinfowler.com/eaaCatalog/

Also here: http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html 也在这里: http//java.sun.com/blueprints/corej2eepatterns/Patterns/index.html

Also, JPA doesn't necessarily eliminate the need for a DAO layer. 此外,JPA不一定消除对DAO层的需求。 Instead, your DAO layer would still build the JPA queries, likely within finder methods, and return the entities that those queries returned. 相反,您的DAO层仍然可能在finder方法中构建JPA查询,并返回这些查询返回的实体。

You could eliminate the DAO layer, and instead hit the JPA entities directly within your business tier, but personally still like to maintain a separate persistence (DAO) and business tier, particularly in those cases where I end up having to mix up some JPA with plain JDBC, etc. 您可以消除DAO层,而是直接在业务层内点击JPA实体,但个人仍然喜欢维护单独的持久性(DAO)和业务层,特别是在我最终不得不混淆一些JPA的情况下普通的JDBC等

There is a great summary of the debate here . 有辩论的大汇总这里 The best answer is that it depends. 最好的答案是它取决于。 If your app is complex, and you may be accessing JDBC directly in some cases (because JPA and ORM tools are not the answer to everything, and are very bad at some things), or if you need to pull data from sources that just don't work well with ORM, you'll need a DAO layer anyway, so in my mind, I'd rather be consistent and use a DAO layer for everything. 如果您的应用程序很复杂,并且您可能在某些情况下直接访问JDBC(因为JPA和ORM工具不是所有内容的答案,并且在某些方面非常糟糕),或者您需要从仅提供数据的来源提取数据与ORM配合得很好,无论如何你都需要一个DAO层,所以在我看来,我宁愿保持一致,并为所有东西使用DAO层。 It's generally not that complex, and it isolates your business logic from your persistence logic, which I believe to be a good thing. 它通常不那么复杂,它将您的业务逻辑与持久性逻辑隔离开来,我认为这是一件好事。 But, it is a matter of personal preference, and if your app is suitably simple, it's probably overkill. 但是,这是个人偏好的问题,如果你的应用程序非常简单,它可能有点过分。

There is a good recommendation of a generic DAO pattern that can be used with JPA here . 有可与JPA使用泛型DAO模式的一个很好的建议在这里 This allows you the benefits of a DAO in that you can always override this for a specific DAO, while keeping the more standard and typical database interactions simpler. 这使您可以获得DAO的好处,因为您可以始终为特定的DAO覆盖它,同时保持更标准和典型的数据库交互更简单。

If you use Java EE 6 (not Java EE 5), then some of technical J2EE patterns are not needed anymore for the task they are used in J2EE. 如果您使用Java EE 6(而不是Java EE 5),则不再需要某些技术J2EE模式来完成它们在J2EE中使用的任务。

For example, use injection instead of ServiceLocator. 例如,使用注入而不是ServiceLocator。

@See http://pawelstawicki.blogspot.com/2010/07/review-real-world-java-ee-patterns.html @参见http://pawelstawicki.blogspot.com/2010/07/review-real-world-java-ee-patterns.html


GOF patterns still required, because they are not (only) related to Java EE. GOF模式仍然需要,因为它们(仅)与Java EE无关。

In general: Patterns have an intend: they want to produce a solution/best practice for an problem, with a given set of functionality that is proviced by the environment (In your case: it is Java, Java EE 6, ...) 一般来说:模式有一个意图:他们希望为问题提供解决方案/最佳实践,并使用由环境提供的一组给定功能(在您的情况下:它是Java,Java EE 6,......)

  • If the problem is gone a way: you do not need the pattern anymore 如果问题消失了:你不再需要这种模式了
  • If the environment has changed since the pattern is fond, then you have to rethink the pattern, because may the problem is gone (first point), or there is now a better way the handle the problem. 如果环境因模式喜欢而发生了变化,那么你必须重新考虑模式,因为问题可能已经消失(第一点),或者现在有更好的方法来处理问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM