[aosd-discuss] can you have interception w/o aop?

Pascal Costanza pc at p-cos.net
Thu Apr 6 04:11:45 EST 2006


On 6 Apr 2006, at 09:03, Roger Johansson wrote:

> Ok, I don't feel that Ive got any real clear answers to the  
> questions yet.
>
> 1) Can you have interception w/o aop?
> Show me a pseudo code example of interception where the  
> interception code is
> not modular in any way
>
> If your base code manually triggers some event , its not  
> interception , then
> its delegation, right?
> Atleast for me interception is when the base (source) code is  
> ignorant of
> the interception mechanism.
> and if the base source code is ignorant of that mechanism the  
> design is
> modular, right?
> thus, whenever you use interception you get AOP?

Here is an example in Scheme:

(define (fib x)
   (if (< x 2)
      1
      (+ (fib (- x 1))
         (fib (- x 2)))))

#;> (let ((fib (lambda (x)
                  (display "fib called")
                  (newline)
                  (fib x))))
       (fib 5))
fib called
8

The local redefinition of fib provides what would be called a before  
advice in AOP terms. The code embedded in the local redefinition is  
"oblivious" in the sense that it doesn't have to change its call to  
fib in order to trigger the "advice".

If you want to have a global effect, you have to use side effects:

(let ((org-fib fib))
       (set! fib (lambda (x)
                   (display "fib called")
                   (newline)
                   (org-fib x))))

#;> (fib 3)
fib called
fib called
fib called
fib called
fib called
3

If you're looking for a more object-oriented style, you can get  
interception by simply using something like the Decorator pattern.  
Also interesting are dynamic proxies in Java, the handling of  
"message not understood" errors in Smalltalk or method wrappers in  
Smalltalk. There are probably countless other approaches.


Pascal

-- 
Pascal Costanza, mailto:pc at p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium







More information about the discuss mailing list