liveBook · Manning

Aspect-oriented programming

As explained in Spring Start Here, Second Edition

Aspect-oriented programming is a programming technique that modularizes behavior applied across multiple program components, such as logging or transaction management.

Aspect-oriented programming (AOP) applies recurring supporting logic to selected method calls. Define that logic once instead of repeating it in business methods, keeping their main responsibilities easier to read and maintain. section 6.0

Design an aspect around three choices:

  • Aspect: the logic Spring executes. section 6.1
  • Advice: when that logic runs, such as before or after a method call. section 6.1
  • Pointcut: which methods Spring intercepts. section 6.1
Figure 6.1 Sometimes it’s not relevant to have parts of the code in the same place as the business logic because it makes the app more difficult to understand. A solution is to move part of the code aside from the business logic implementation using aspects. In this scene, Jane, the programmer, is discouraged by the logging lines written together with the business code. Count Dracula shows her the magic of aspects by decoupling the logs into an aspect.

The figure contrasts logging mixed into business code with logging separated into an aspect. section 6.1

How Spring Start Here, Second Edition covers it

How deep it goes
Defines aspects, advice, and pointcuts, while stopping short of implementation details.
Examples
Uses logging, permission checks, execution-time measurement, and transaction management as examples.
What it assumes
Assumes familiarity with the Spring context and dependency injection.
What you can do after
Evaluate whether recurring non-business logic should be separated to reduce duplication and improve readability.
How it connects
Connects to dependency injection, the Spring context, transactions, and security.

Also explained in

Compare how 2 books explain aspect-oriented programming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.