O'Reilly logo

AspectJ Cookbook by Russ Miles

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

23.2. Applying the Director Design Pattern

Problem

You want to define a set of roles to be implemented by unknown sets of application classes so they can be interacted with generically by an abstract aspect.

Solution

Apply the Director aspect-oriented design pattern. Figure 23-2 shows the key components of the Director pattern.

The structure of the Director pattern

Figure 23-2. The structure of the Director pattern

The key roles in the Director pattern shown in Figure 23-2 are:

DirectorAspect

The abstract aspect at the center of the design pattern that specifies the roles to be directed using Java interfaces and optionally specifies interactions that can occur between those roles.

Role1 and Role2

A pair of example roles defined as nested interfaces within the abstract DirectorAspect.

BusinessClassA and BusinessClassB

A pair of business classes within the target application that are candidates for the roles defined by the DirectorAspect.

SpecializedAspect

Applies the roles to specific classes within the target application. In this example, Role1 is applied to BusinessClassA and Role2 is applied to BusinessClassB. When BusinessClassB does not implement the bar( ) method necessary for the Role2 interface, this can be supplied using static cross-cutting techniques by the SpecializedAspect.

Discussion

The Director pattern decouples the generic and reusable aspect behavior from the implementation classes of a specific application, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required