Implementations should follow the design goals of cross-cutting concerns by maintaining consistency, not being scattered, and not being tangled. There are several different approaches that can be taken when implementing cross-cutting concerns. These include DI, the decorator pattern, and AOP.
Implementing cross-cutting concerns
Using dependency injection (DI)
One approach to handling cross-cutting concerns is to use the DI pattern, which we covered in Chapter 6, Software Development Principles and Practices. This pattern can be used to inject cross-cutting dependencies into classes that need them. This allows us to write loosely coupled code and avoid scattering. The logic for the cross-cutting concern will not be duplicated...