[Xotcl] Filter Chaining Question

Uwe Zdun uwe.zdun@uni-essen.de
Mon, 16 Jul 2001 11:27:49 +0200


On Sunday 15 July 2001 21:45, you wrote:
> Subject: The Adapter pattern inplemented with filters(code from
> distribution)
>
> The code below from the XOTcl distribution is given below.
> Suppose the class Adapter has another filter "filter2"
> registered after the filter "adapterFilter".
> My understanding of the code(below) is that only requests that
> are not found in specificRequest will be filtered by
> filter2.

yes ... that is correct for the Adapter implementation below. Usually you 
would prepend filter2 before adapterFilter (with filter "filter2 [[self] info 
filter]") in order to ensure that filter2 is called before adapterFilter.

However, if this does not work for you, you can also refine the Adapter 
implementation to your requirements. Say, by calling next before 
adapting to the adaptee ...

--uwe 



> ..........................................................
>
> Question:
> If my understanding is correct, how can I  have all
> messages/requests to Adapter be filtered by both filters.
> ..........................................................
>
> Code from distribution:
>
> Class Adapter -superclass Class
>
> Adapter metadata add description
>
> Adapter metadata description {
>   Simple adapter pattern meta-class taken from the paper
>   'Filters as a Language Support for Design Patterns in
>   Object-Oriented Scripting Languages'.
> }
>
>
> Adapter instproc adapterFilter args {
>     # Appears that filter args == args of triggering method
>     set r [self calledproc]
>     [self] instvar specificRequest adaptee
>     #puts [self]
>     if {[info exists specificRequest($r)]} {
>         #puts $args
>         return [eval $adaptee $specificRequest($r) $args]
>     }
>     next
> }
>
> Adapter instproc init args {
>     [self] filterappend [self class]::adapterFilter
>     next
>     [self] instproc setRequest {r sr} {
>  [self] set specificRequest($r) $sr
>     }
>     [self] instproc setAdaptee {a} {
>  [self] set adaptee $a
>     }
> }
>
>
> _______________________________________________
> Xotcl mailing list  -  Xotcl@alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl

-- 
Uwe Zdun
Institute for Computer Science, University of Essen
Phone: +49 201 81 00 332, Fax: +49 201 81 00 398
zdun@{xotcl,computer,acm}.org, uwe.zdun@uni-essen.de