Aspect-Oriented Programming

Thanks to decorators, you can actually develop applications using Aspect-Oriented Programming (AOP). AOP is a programming paradigm that we haven't had the chance to discuss yet. It is a technique that is meant to deal with cross-cutting concerns.

The idea of AOP is to implement the logic for cross-cutting concerns once and reuse it declaratively​ and, as we've just seen, this is exactly what decorators enable us to do!

By adding decorators to elements, you can instrument those. For example, you could create and use a decorator for all your service methods, ensuring that logging is performed before/after each method call.