# $Id: s.adapter.xotcl 1.5 01/03/23 21:55:33+01:00 neumann@somewhere.wu-wien.ac.at $
package provide xotcl::pattern::adapter 0.9

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 { 
    set r [self calledproc]
    [self] instvar specificRequest adaptee \
	[list specificRequest($r) sr]
    if {[info exists sr]} {
	return [eval $adaptee $sr $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
    }
}
