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.*);
void set...(...)
is the joinpoint
As you know an Aspect is the association of a Concern, a Pointcut and a Joinpoint
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:
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:
Within .NET there are a number of established techniques for implementing the pointcut: