liveBook · Manning

Aspect-oriented programming

As explained in Grokking Software Architecture

A programming technique that modularizes cross-cutting concerns and automatically applies them at designated join points in program execution.

Aspect-oriented programming (AOP) separates uniform cross-cutting concerns, such as logging, from business logic. A framework weaves that logic into selected methods at runtime or compile time. section 4.3.2 section 4.5.3

Logging an order service

A plain OrderService can keep saveOrder focused on business logic. A framework can weave a log call before the method runs, without adding that call to the service itself. section 4.3.2

class OrderService
{
    // The framework magically injects or provides access to this
    saveOrder(order) {
        _logger.Log("Executing SaveOrder..."); // <-- "Woven" in
        // Just pure business logic...
    }
}

See the woven version: the framework adds a log call before saveOrder’s business logic. section 4.3.2

AOP suits uniform behavior, but it is not a cure-all: woven logic may lack useful business context, and extensive weaving can add build size and runtime overhead. For simpler cases, injecting a shared service is another way to keep concerns separate. section 4.3.2 section 4.5.3

How Grokking Software Architecture covers it

How deep it goes
Defines runtime or compile-time weaving, demonstrates method logging, and notes overhead and limited access to business context.
Examples
Shows a framework weaving a log call into OrderService.saveOrder.
What you can do after
Evaluate AOP as an automated option for uniform cross-cutting behavior, weighing cleaner business logic against overhead and limited data context.
How it connects
Connects cross-cutting concerns, separation of concerns, dependency injection, and layered architecture.

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 Grokking Software Architecture. The section links point to the parts of the book it draws on.