# $Id: s.adapter.xotcl 1.4 01/03/23 22:24:35+01:00 neumann@somewhere.wu-wien.ac.at $
Class Adapter -superclass Class  

@ @File {
  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 adaptee specificRequest 
  if {[info exists specificRequest($r)]} {
    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
  }
}
