Re: can you have interception w/o aop?

Pascal Costanza <[email protected]>
Newsgroups gmane.comp.programming.aspect.general
Message-ID <[email protected]>
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:[email protected], http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium





__________________________________________________
AOSD Discuss mailing list    -    [email protected]
To unsubscribe go to http://aosd.net

Check out the AOSD.net Wiki: http://aosd.net/wiki
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.