File: simpleFilters.xotcl

package info (click to toggle)
xotcl 0.85.3-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,832 kB
  • ctags: 2,734
  • sloc: ansic: 18,065; tcl: 1,256; makefile: 653; sh: 430
file content (57 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# $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 {}