Chapter 19. Implementing Behavioral Object-Oriented Design Patterns


The final category in this trio of design pattern chapters investigates how behavioral patterns can benefit from an aspect-oriented implementation.

Behavioral patterns are generic guidelines for structuring interactions and locating behavior throughout the participating classes. The recipes in this chapter show that these design patterns can gain considerable architectural advantages from using aspect orientation.

As with the structural patterns from the previous chapter, some GoF patterns simply don’t seem to benefit significantly from aspects. In the case of behavioral aspects, this means that the Interpreter design pattern is not included in this chapter although the research, being completed by Jan Hanneman at, may uncover approaches that further refine the mechanisms presented in this chapter and perhaps lead to improvements that can be made to the interpreter patterns implementation using aspect orientation.

19.1. Implementing the Observer Pattern


You want to apply the observer pattern using AspectJ.


The observer pattern allows the designer to create dependencies between objects such that if one object’s state changes the other objects will be notified and may act accordingly.

Example 19-1 uses the Director aspect-oriented design pattern (see Chapter 23) to provide a generic aspect implementation of the observer pattern.

Example 19-1. Defining the observer ...

Get AspectJ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.