Aspect-Oriented Programming
Some concerns don't belong to any one class — logging, security checks, transaction handling, performance timing. Implemented the ordinary object-oriented way, that code ends up copy-pasted into every method that needs it, crosscutting the whole codebase instead of living in one place. Aspect-oriented programming (AOP) gives that crosscutting code its own module: an aspect.
The Problem It Solves
Imagine adding "log every call to every method that touches money" to a banking system by hand. You'd edit deposit, withdraw, transfer, and every method like them, in every class, forever — and remember to do it again for each new one. That's tangled code (the logging is tangled into the business logic) and scattered code (the same few lines are duplicated everywhere they're needed). AOP's answer: write the logging once, in one aspect, and declare which methods it applies to.
Core Vocabulary
| Term | Meaning |
|---|---|
| Join point | A point in a program's execution the aspect can hook into — typically a method call. |
| Pointcut | An expression that selects which join points an aspect applies to (e.g., "every method in the Account class"). |
| Advice | The code that actually runs at a matched join point — before, after, or around it. |
| Aspect | The module bundling a pointcut with its advice — the unit AOP adds on top of your classes. |
| Weaving | The process that combines aspects with ordinary code — at compile time, class-load time, or runtime, depending on the implementation. |
Representative Languages
AOP appears as a full language extension, as a framework feature and as a language idiom.
| Language | Why study it |
|---|---|
| AspectJ | The reference implementation: aspect, pointcut and advice as first-class Java syntax. |
| Spring AOP | Proxy-based AOP built into Spring, the way most Java developers meet aspects. |
| PostSharp | Compile-time aspects for C# and .NET applied by attributes. |
| Python decorators | Not "AOP" by name, but the same idea in miniature: @log_calls above a function adds behavior without editing its body. |
See it in a full demo: Demo 10 — AspectJ.
The Trade-off
AOP's own strength is also its biggest complaint: because advice runs "invisibly" — nowhere near the method it affects, in the source code you're reading — it can make control flow genuinely hard to follow. Most teams reach for AOP only for a short list of clearly cross-cutting concerns (logging, metrics, transactions, security), and keep ordinary business logic in ordinary, visible method calls.