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

22.1. Applying Development Guidelines and Rules

Problem

You want to control what programmatic constructs are allowed in your application by providing a policy that is enforced at compile time.

Solution

Use the Border Controller aspect-oriented design pattern to declare a set of regions within your code. Reuse those regions when declaring any top-level rules for your project in an aspect according to the Policy pattern. Optionally extend your projects’ top-level policies to specialize them for particular regions of your application.

Discussion

This solution gives you a sneak preview of two of the aspect-oriented design patterns coming in Chapter 23. Providing the foundation for this recipe’s solution, the Border Controller design pattern allows you to capture your application’s architecture as a set of reusable pointcuts that declare important regions within your code. Those regions can be referenced throughout the rest of the aspects in your application.

The BorderControllerAspect shown in Example 22-1 declares four regions within an example application: the withinTestingRegion() region incorporates the packages where testing code is located, withinMyApp() specifies the packages and subpackages that make up your application, withinThirdParty() specifies any areas where you may be using third-party source code, and withinMyAppMainMethod() conveniently declares the location of the main(..) method for your application.

Example 22-1. Providing a foundation for your project and application’s ...

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