13

With the arrival of Java EE and EJB 3,

  1. have any of these Core J2EE Patterns become obsolete, or stand deprecated in light of (better) alternatives?

  2. Are there any new patterns that one could use?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Harry
  • 3,684
  • 6
  • 39
  • 48

2 Answers2

17

Adam Bien has written an excellent book "Real World Java EE Patterns - Rethinking Best Practices" just about this (i.e. updating J2EE patterns to Java EE 5/6). You can see a an overview of the changed and updated J2EE patterns in my Summary of the Real World Java EE Patterns.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Jakub Holý
  • 6,019
  • 3
  • 33
  • 33
4

Some patterns such as Session Facade still make sense to me. We still need to take care in the of public interfaces and focus on a Facade is helpful for that purpose. The "Session"-ness tends to be less prominent because we simply can annotate a POJO to get the EJB, but the "Facade"-ness is critical.

Service Locator has been pushed down into the annotation-based injection approach for resource access. So it's not so much unimportant as more nicely wrapped in the Java EE framework.

Data Transfer Objects are less widely used, JPA-annotated POJOs, replacing Entity Beans are quite commonly used. There is some debate in this area, in some scenarios DTOs may still be useful, but in simple cases they are probably not needed, and hence there may be less use of related patterns such as Transfer Object Assembler.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
djna
  • 54,992
  • 14
  • 74
  • 117
  • +1. You mention four: session facade, service locator, DTO, and TOA. You also say,"Some patterns ... still make sense to me". Does that mean other patterns do not make (so much) sense in the context of JEE to you (or, others)? – Harry Apr 17 '10 at 04:08
  • 1
    I didn't make much use of Service To Worker or Dispatcher View, so I don't know whether JEE/EJB3 had any impact. Service Locator and DTO I used to use and see them as less necessary now. – djna Apr 17 '10 at 21:04
  • Appreciate your answers. I'm still hoping that readers will consider supplementing what you have written so far and make the answer more complete than it is now wrt other patterns. Will hold off marking the answer as final till then. Thanks again... – Harry Apr 18 '10 at 04:56
  • DTOs are still usable when unit testing EJBs outside the container. Its typically far easier to mock a DTO than mocking the EntityManager. – Lars Tackmann Apr 18 '10 at 20:28
  • @Lars, a touch of devil's advocacy: A JPA object is a POJO with annotation. So in an environment where annotations are not processed, such as outside a container, what difference is there between a JPA-ed bean and a DTO? – djna Apr 19 '10 at 12:47