Java Reference
In-Depth Information
11
WHAT'S IN THIS CHAPTER?
How to implement the observer pattern in plain code
How the observer pattern works in the real world
How to implement the observer pattern using @Observes and
Event i ring
How to use qualii ers to gain i ne‐grain control over observers
How to implement transaction‐sensitive observers and rollbacks
WROX.COM CODE DOWNLOAD FOR THIS CHAPTER
The wrox.com code download for this chapter is found at www.wrox.com/go/
projavaeedesignpatterns o n the Download Code tab. The code is in the Chapter 11
download and individually named according to the names throughout the chapter.
The observer pattern is one of the most widely used and accepted design patterns in
modern programming languages, software, and user interface (UI) frameworks. Most
programming languages use observers within their internal application programming
interfaces (APIs), and Java is no exception. But Java EE goes further than most and provides
a default implementation of the observer pattern, so developers can use this pattern without
implementing it from scratch. This chapter focuses on Java's default implementation of the
observer pattern: where it is used, how observers are implemented via annotations in Java EE,
and how observers can be made transaction sensitive.
WHAT IS AN OBSERVER?
The idea behind the observer pattern is that an object that changes its state can inform other
objects that a change has occurred. In the language of the design pattern, the object that
 
Search WWH ::




Custom Search