Terminology: advice
I continue to try and cut through some of the confusion around AOP by providing simple definitions and examples of often obtuse terminology (see also: other terminology posts).
Today's term: advice.
An advice is simply the code that could be executed at a pointcut. For instance, if you want to do some logging, then your advice is the code that performs the logging. If you are wrapping methods inside of a transaction, then your advice is whatever implementation of begin/commit/rollback you are using. And so on...
Here's a quick example of a tracing aspect I borrowed from the PostSharp site:
There's two advices in that aspect:
- One to write "Entering" and the method name to the trace, using Trace.TraceInformation(...)
- One to write "Exiting" and the method name to the trace, using Trace.TraceInformation(...)
Those are both very trivial advices, of course. A more complex advice could reference services, perform logic, use a lot more context information than just method name, etc.
So now that you know what a join point, a pointcut, and an advice is, you have all the puzzle pieces. The final step is to put them all together. And guess what it's called when you put them all together? (spoiler alert: it's the "A" in "AOP")