Chapter 18. Implementing Structural Object-Oriented Design Patterns

Introduction

Continuing on from the creational design patterns in the previous chapter, you are going to harness the advantages in implementing structural design patterns using AspectJ.

Although the benefits of applying aspects vary depending on the specific pattern, structural object-oriented (OO) design patterns gain more from aspects than their creational cousins. This is mostly due to the cross-cutting and generic nature of structural design patterns which tends to lend itself nicely to aspect-oriented implementations.

Unfortunately, aspect orientation does not provide any real benefits when designing or implementing the façade pattern. The goal of the façade is to provide a simpler interface to a larger collection of objects of complex components. This goal can be achieved in a system where the source code is known using standard classes and method calls, requiring none of the additional mechanisms of AspectJ.

18.1. Implementing the Composite Pattern

Problem

You want to apply the composite pattern using AspectJ.

Solution

The composite pattern provides the capability to group objects together in a collection and interact with the group as a whole in a similar manner as you would interact with an individual member of the group.

Example 18-1 uses the Director aspect-oriented design pattern (see Chapter 23) to provide a generic implementation of the composite pattern using AspectJ.

Example 18-1. Using an aspect to define ...

Get AspectJ Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.