Chapter 5: Dependency Injection and CDI

In this chapter we introduce the concept of dependency injection and why it is so important in Java EE. The we go on to show how to implement dependency injection in Java SE.

We continue by discussing how dependency injection is implemented in Java EE and introduce context dependency injection by discussing the key differences between context dependency injection and the enterprise Java bean container.

Professional Java EE Design Patterns

Chapter 5: Dependency Injection and CDI

Chapter 6: Factory Pattern

In this chapter we discuss what the factory pattern is and why you need it.

How to implement the various flavours of the factory pattern: the factory method and the abstract factory and how to implement the factory pattern in Java EE using the @Producers and @Inject annotations.

We finish by discussing how to create custom annotations and how to use the @Qualifier annotation to disambiguate concrete implementations.

Professional Java EE Design Patterns

Chapter 6: Factory Pattern

Chapter 7: Decorator Pattern

In this chapter we discuss how to implement the decorator pattern in Java SE and how the decorator pattern solved a real‐life dilemma.

We show how to implement the decorator pattern using the @Decorator and @Delegate annotations and how to use qualifiers to gain fine‐grain control over how decorators are used.

Finally we discuss how to make the decorator pattern pluggable via the deployment descriptors

Professional Java EE Design Patterns

Chapter 7: Decorator Pattern

Chapter 11: Observer Pattern

In this chapter we show how to implement the observer pattern in Java SE and how the observer pattern works in the real world.

We then show how to implement the observer pattern in Java EE by using the @Observes annotation and Event firing.

We finish by showing how to use qualifiers to gain fine‐grain control over observers and how to implement transaction‐sensitive observers and rollbacks.

Professional Java EE Design Patterns

Chapter 11: Observer Pattern