

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



PHP , pasted on Sep 21:

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 <?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

" , $b -> getfoo ()); printf ( "Calling Foo() as Foo(): %s

" , $b -> getFoo ()); printf ( "Calling Foo() as FOO(): %s

" , $b -> getFOO ()); printf ( "Calling bar() as bar(): %s

" , $b -> getbar ()); printf ( "Calling bar() as Bar(): %s

" , $b -> getBar ()); printf ( "Calling bar() as BAR(): %s

" , $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