Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The problem of creating instances is common, so the solution is relatively easy. There are many different ways to do this, but we take the easiest route (and not the most flexible, mind you) by creating an AuditFacadeFactory class. This refactoring is an example of the Implementation Factory pattern, which states that we should use factories to create a modules implementation classes. Now, instead of the AuditAction creating the AuditFacade implementation, it invokes the factory and is returned an instance, as shown in Listing 7.9. An alternative, and possibly a better solution, would have been to inject the appropriate AuditFacade implementation into the AuditFacade using a dependency injection framework, such as Spring.