23

Can someone explain AOP concepts for dummies: join point, point cut, weaving etc.

For example: Aspect: a modularization of a concern that cuts across multiple classes. What does that mean?

2 Answers 2

17

Think of a concern as a functionality group e.g. logging, auditing, security

These functionalities are ever present in most code, but they don't really live in our animal->dog classes - they are functionality that should live in many classes - they are cross cutting concerns.

  • A Joinpoint is a place in the code where the aspect code is actually ran.

  • A pointcut is how to say what code runs at the jointpoint.

  • Weaving - is when the compiler/system takes your normal code and includes all the AOP code so that it triggers the correct code etc - can think of this as an extra pre-compile step.

A simple understandable example is:

  1. We want to track all method calls for debugging purposes (i.e. We want to see which methods get called in what order).
  2. We create an aspect that logs the name of the method when it gets called
  3. We create pointcuts that associate the aspect with all methods in the code. In most AOP frameworks you can do this easily with some wild cards
  4. We now have logging of every method ever called.

Please be aware that terminology differs slightly between different implementations and AOP frameworks.

7
  • Just as I was writing my lengthy answer! Yours is more concise, I like it. Will edit it slighty for clarity. Aug 8, 2011 at 16:09
  • Thanks, I should learn the formatting rules, keep forgetting.
    – Jonno
    Aug 8, 2011 at 16:15
  • Seems like this would be simple to implement with Python decorators or Lisp macros- Y/N ? Aug 8, 2011 at 16:39
  • @Paul - not familiar with either construct you mention I'm afraid and a quick google didn't give me enough insight to answer either way.
    – Jonno
    Aug 8, 2011 at 17:25
  • @PaulNathan: AOP is pretty simple in dynamic languages. A simple AOP framework can be created in an afternoon. In compiled languages like Java life is not so sweet. Oct 14, 2014 at 17:06
1

Read in sequence

Each definition builds on the previous ones.

Cross cutting concern

Something that bothers you (concern) everywhere (cross-cutting) across you application. e.g logging or security

Aspect

A chunk of code that is automatically added before, after, or both (around) your existing code

PointCut & JoinPoint

                  Application code
                           |
                           |
                           |
                           |
                          \|/
                           |
JoinPoint  ----------->("before" aspect, on the way in)  // just before your intercepted application code
Pointcut start--------> public String myMethod(params ...)
                   //your application code
Pointcut finish--------> return (foo)
JoinPoint  ----------->("after" aspect, on the way out)  // just after your intercepted application code
                           |
                          \|/
                           |
                           |
                           |
                  Application code

Pointcut

A place in code execution where part of the aspect execute.

JoinPoint

The point where your aspect "joins" the pointcut. At a "before" joinPoint you will have access to parameters, at "after" joinPoint you will have access to the return value. If an exception is thrown, you may need a "try-catch-finally" to handle or re-throw it.

Weaving

The process of adding aspects around a pointcut

1
  • Whoever voted my answer down, please leave a comment why - if you don't mind. I promise I will not start an argument over it. I would, however like to know what I could have done better. Thank you!
    – Prashant
    Apr 6, 2019 at 16:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.