Terminology: aspect
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).
"Aspect" seems like the core term in "aspect oriented programming" doesn't it? An aspect is simply a way to indicate to an AOP tool: what and where. The "what" is the advice, and the "where" are join points.
Let's review the terms covered so far by looking at a very trivial example of AOP:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyClass | |
{ | |
[MyAspect] | |
public void MyMethod() | |
{ | |
Console.WriteLine("inside of my method"); | |
} | |
} | |
[Serializable] | |
public class MyAspectAttribute : OnMethodBoundaryAspect | |
{ | |
public override void OnEntry(MethodExecutionArgs args) | |
{ | |
Logger.Write("some logging message"); | |
} | |
} |
In that example:
- The join point is "OnEntry", i.e. before a method is executed
- The advice is the body of the OnEntry method (Logger.Write(...))
- The aspect is the MyAspectAttribute class itself
- The pointcut is a combination of the applied [MyAspect] attribute along with the join point
- i.e. the complete pointcut is "before the MyMethod method of MyClass is executed"
- in this illustration, it's a very specific pointcut, but useful real-world pointcuts would be broader
- The cross-cutting concern is logging (haven't gotten to that term yet; what's the rush, it's only the name of the site!)
- The weaving is performed by the PostSharp post-compiler (also haven't gotten to that term yet)
Looks like two more terminology posts to go. If there's a term that I'm missing or glossing over, let me know, and I'll write a post on it.