Sun Oct 26, 2008 11:49 pm
<?php
class PersonWriter {
function writeName( Person $p ) {
print $p->getName()."\n";
}
function writeAge( Person $p ) {
print $p->getAge()."\n";
}
}
class Person {
private $writer;
function __construct( PersonWriter $writer ) {
$this->writer = $writer;
}
function __call( $method, $args ) {
if ( method_exists( $this->writer, $method ) ) {
return $this->writer->$method( $this );
}
}
function getName() {
return "Joe";
}
function getAge() {
return 44;
}
}
$person= new Person( new PersonWriter() );
$person->writeName();
$person->writeAge();
?>
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.