Join Points in Aspect Oriented Programming

991 Views Asked by At

I am currently studying about AOP and the important parts of it which are Advice, Pointcuts, and Join Points. I read a very understandable explanation about what is Advice and Pointcuts from this links. Aspect Oriented Programming vs. Object-Oriented Programming

However, I have a difficulty is understanding what Join Points is. From what I read, Join Points is the well-defined locations in the structure of a program where an aspect can weave in its advice code.

But, when it comes the the real example, I could not find any good example to understand the example of Join Points.

As taken from the example in the link above, if Advice and Poincuts are what written below, than where do we define the Join Points?

Classical Approach:

void set...(...) {
    :
    :
    Display.update();
}

Advice:

after() : set() {
   Display.update();
}

Poincuts:

pointcut set() : execution(* set*(*) ) && this(MyGraphicsClass) && within(com.company.*);
1

There are 1 best solutions below

0
On BEST ANSWER

void set...(...) is the joinpoint


As you know an Aspect is the association of a Concern, a Pointcut and a Joinpoint

  • The implementation of a cross-cutting concern is called the Concern.
  • The well defined location within a class where a concern is going to be attached is the Joinpoint.
  • The place where the joinpoint(s) are specified, either through configuration or code, is the Pointcut.

A Concern is something that is important to one or more stakeholders. Additionally concerns can conceptually be divided into two categories (the implementation for each can be the same):

A side effect: a concern which is not changing the behaviour at the joinpoint, but instead introduces additional actions.

A logging concern is a good example of a side effect,

e.g. each call to the targeted method (this is the joinpoint) BankWithdrawalHandler.Execute(ICommand command) will first call the concern LoggingConcern.Execute(ICommand command)

which will be able to run before and after the Execute method, logging such things as start time/end time/total time/in parameters/out parameters etc.

A side effect can:

  • Inspect/capture the input parameters at the targeted pointcut as required and action any additional processing
  • Inspect/capture the output result at the targeted pointcut as required and action any additional processing

An advice: a concern which will potentially change the input and/or output of the targeted method.

A caching concern is a simple example - e.g. whenever the run-time executes the targeted method (this is the joinpoint) Repository.Find<T>(long id) the method CacheConcern.Find<T>(long Id) will be configured to run first and only allow the call to continue on to the Repository.Find() method if the value is not found in the cache.

An advice can:

  • Inspect the input parameters at a targeted pointcut and modify them if needed
  • Cancel or avoid the execution of the targeted method and replace it with a different implementation
  • Inspect the output result of the targeted method and modify or replace it as required

Within .NET there are a number of established techniques for implementing the pointcut:

  • Post build IL weaving/PostSharp
  • Dependency Inversion (Inversion of Control (IoC) and Dependency Inversion (DI))
  • Interception/DynamicProxy