[ create a new paste ] login | about

Link: http://codepad.org/c7ewg1yc    [ raw code | output | fork ]

PHP, pasted on Sep 21:
<?php  

class TheActualIterator implements Iterator { 
 
  function current() {} 
  function key() {} 
  function next() {} 
  function valid() {} 
  function rewind() {} 
 
  function getFoo() { return 'this is ' . get_class($this); }

  function getbar() { return 'this is ' . get_class($this); }

}

class SomeRandomDecorator extends filteriterator {
  function accept() { return true; }
}
 
$a = new TheActualIterator();
 
$b = new SomeRandomDecorator($a);

printf("Calling Foo() as foo(): %s\n", $b->getfoo());
printf("Calling Foo() as Foo(): %s\n", $b->getFoo());
printf("Calling Foo() as FOO(): %s\n", $b->getFOO());

printf("Calling bar() as bar(): %s\n", $b->getbar());
printf("Calling bar() as Bar(): %s\n", $b->getBar());
printf("Calling bar() as BAR(): %s\n", $b->getBAR());


Output:
1
2
3
4
5
6
Calling Foo() as foo(): this is SomeRandomDecorator
Calling Foo() as Foo(): this is TheActualIterator
Calling Foo() as FOO(): this is TheActualIterator
Calling bar() as bar(): this is SomeRandomDecorator
Calling bar() as Bar(): this is TheActualIterator
Calling bar() as BAR(): this is TheActualIterator


Create a new paste based on this one


Comments: