variable. Want to create a singleton? Just add the @Singleton annotation to the top of your class
i le. Need to implement the factory pattern? Just add the @Produces annotation, and the method
will become the factory of the given return type.
Java EE also sets the standards. The @Inject annotation serves as a default implementation and can
be mixed and matched with almost any other framework (the Spring Framework) because they use
the same annotation.
When Patterns Become Anti‐Patterns
Design patterns represent collected wisdom, but this doesn't mean you have to use them all the
time. Just like the famous American psychologist Abraham Maslow 7 so aptly stated, “If the only
tool you have is a hammer, you tend to see every problem as a nail.” If you try to address all prob-
lems with only the patterns you know, they simply won't i t, or worse, they'll i t badly and cause
more problems. Even more, unnecessary use of patterns tends to overcomplicate the system and
result in poor performance. Just because you like the decorator pattern does not mean you need to
implement the pattern on every object. Patterns work best when the conditions and the problems
require their use.
Java and design patterns have had a long journey to arrive at where they are now. Once they were
separate, with no knowledge of each other, but now they are together, to be forever integrated in the
Java Enterprise Edition. To understand this intimate paring, you must know their history. Already
you have discovered the roots of your favorite couple and how they found each other. You've read
about J2EE's rocky beginnings and how the GoF gave light to 23 design patterns. You've seen how
frameworks like Spring came up behind Java and took over and how the reinvented Java EE is now
i ghting back and gaining ground. The knowledge contained in this topic will prepare you to tackle
with coni dence the majority of the design issue that you will face during your development career.
You can rest easy knowing that the years of struggle the Java Enterprise Edition has endured com-
bined with the inherent wisdom of design patterns have resulted in an endurably strong and l exible
programming language and environment.
Enjoy this invaluable guide to design patterns in Java EE, and use the wisdom gained here in every
project you're involved in.
1. Design Patterns: Elements of Reusable Object‐Oriented Software (Addison‐Wesley, 1994):
Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides.
2. According to the TIOBE index, Java appears at number two after C: http://www.tiobe.com/
3. Before version 5, Java EE used to be called J2EE. From this point J2EE will be used to refer to
pre‐Java EE 5.