# $Id: s.simpleFilters.xotcl 1.3 01/03/23 22:24:35+01:00 neumann@somewhere.wu-wien.ac.at $

@ @File {
  description {
    Some simple examples of filters taken from the paper 
    'Filters as a Language Support for Design Patterns in
    Object-Oriented Scripting Languages'. They demonstrate filters,
    filter chains and filter inheritance.
  }
}

Class A
A metadata add description
A instproc Filter-1 args {
  puts "  pre-part of [self proc]"  ;# pre part
  next                            ;# next call
  puts "  post-part of [self proc]" ;# post part
}
A instproc printSomething args {
    puts "  actual called proc: [self proc]"
}
A a1

A filter Filter-1
#a1 set x 1

puts "A call surrounded by pre/post messages:"
a1 printSomething

A filter {}
A instproc Filter-2 args {
    puts "  only a pre-part in [self proc]" 
    next
}
A instproc Filter-3 args {
    next
    puts "  only a post-part in [self proc]" 
}
A filter {Filter-1 Filter-2 Filter-3}

puts "Now a filter chain:"
a1 printSomething

Class B -superclass A
B instproc Filter-B args {
    puts "  entering method: [self proc]" 
    next
}
B b1; B b2
B filter Filter-B

puts "And finally inheritance:"

b1 printSomething

B filter {}
A filter {}