aspose file tools*
The moose likes Spring and the fly likes Joinpoint and Pointcut Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Joinpoint and Pointcut" Watch "Joinpoint and Pointcut" New topic
Author

Joinpoint and Pointcut

Paras Jain
Ranch Hand

Joined: Feb 26, 2005
Posts: 137
Ramnivas,
On a lighter note I have one more question. Directly or indirectly I am using AOP for quite some time in my Spring app. But theoretical when it comes to distinguish between various terminologies aspect, advice, pointcut, joinpoint; I get confused.

Is there any easy way to remember it?


Regards,
Paras


Paras Jain
SCJP 5.0
Ramnivas Laddad
Author
Ranch Hand

Joined: Jul 23, 2003
Posts: 62
You can think of
- aspect as a class-like concept.
- advice as an automatically called method
These two are usually understood easily.

Join point and pointcut concept take a bit longer. One way to think:
- Join points are like rows in database--they just exists much the same way methods just exists.
- Pointcuts are like SQL statements--they select join points just as SQL selects rows.

I hope this helps.

-Ramnivas


Ramnivas Laddad
Author, AspectJ in Action (http://manning.com/laddad2)
Twitter: ramnivas
Paras Jain
Ranch Hand

Joined: Feb 26, 2005
Posts: 137
Thanks Ramnivas. Yes it definitely helps.

Just to make sure my understanding is clear. Let's take example of logging aspect. I want to log before all methods starting with 'test'. (Hypothetically, not sure whether you can do based on method pattern)

Aspect - It's like calling logging framework, the Process of logging
Advice - I am advising the AOP to call log methods on logging framework, like a method

Joinpoints - are actually beginning of methods, AOP intercepts at this point to do some other stuff. i.e. beginning of methods testA(), testB(), testC(), somethingElseD(), somethingElseE()
Point cuts - Pointcut selects those joinpoints based on your aop settings, i.e. out of all the methods select testA(), testB() and testC() and intercept only those.

Is that correct?


Regards,
Paras
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

When teaching this I use the terms

A JoinPoint is any Method in your app's code that you wrote whether you were using AOP or not.
An advice is code you want to run when that JoinPoint method is being called, without adding the code directly into your app's method.
An Aspect is the class that holds the advice code.

A Pointcut is telling AOP which Joinpoints you want your advice code to run with/on.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Aspect: an aspect, a feature
Join point: a point that aspects can join.
Advice: an aspect joins at a point and advices somebody at that point, the latter action is called ... "advice".
Pointcut: draw line to cut points, aspect will advice somebody at the cut points

Hope this helps.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Ramnivas Laddad
Author
Ranch Hand

Joined: Jul 23, 2003
Posts: 62
Mark already clarified, but I will add a bit more...

Paras Jain wrote:
Aspect - It's like calling logging framework, the Process of logging

More like aspects is a programming element that hold all other AOP programming elements -- pointcuts, advice etc.

Advice - I am advising the AOP to call log methods on logging framework, like a method

Advice is extra code that you want to invoke when you reach points selected by your pointcut

 
 
subject: Joinpoint and Pointcut