Skip to main content

Terminology: pointcut

February 08, 2012 mgroves 0 Comments
Tags: pointcut terminology

I'm trying to 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: pointcut.

A pointcut is a simply a set (or an expression that returns a set) of join points. If a join point is a single line between two boxes on a flowchart, then a pointcut would be a description of a set of those lines.

For instance, if you wanted to put some logging after every time a method in a given class was called, you'd first get a pointcut of all the join points that occur after each method. If there are 5 methods in your class, you have 5 join points that make up the specified pointcut.

So if your aspect defines "OnExit", and you apply that aspect to a class "CustomerRepository", then your pointcut is "whenever a method in CustomerRepository exits". You could narrow that to a single method, or expand it to an entire namespace.

As an exercise, let's examine this snippet of code:

obj1.Method1();      // obj1 is of type Class1
obj1.Method2();
obj2.MethodA();      // obj2 is of type Class2

And now a flow chart of that, identifying exit join points:

join points flowchart

So which of those join points would be included in a pointcut of "exiting a method of Class1"? Answer:

Pointcut on flowchart

Comments

Matthew D. Groves

About the Author

Matthew D. Groves lives in Central Ohio. He works remotely, loves to code, and is a Microsoft MVP.

Latest Comments

Twitter