You want to control what programmatic constructs are allowed in your application by providing a policy that is enforced at compile time.
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.
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.
BorderControllerAspect shown in Example 22-1 declares four regions within an example
withinTestingRegion() region incorporates the packages where testing code is
withinMyApp() specifies the packages and subpackages that make up your
withinThirdParty() specifies any areas where you may be using third-party
source code, and
withinMyAppMainMethod() conveniently declares the location of the
for your application.
Example 22-1. Providing a foundation for your project and application’s ...