Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/Delegates/PHP/delegates.php
Normal file
25
Task/Delegates/PHP/delegates.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
class Delegator {
|
||||
function __construct() {
|
||||
$this->delegate = NULL ;
|
||||
}
|
||||
function operation() {
|
||||
if(method_exists($this->delegate, "thing"))
|
||||
return $this->delegate->thing() ;
|
||||
return 'default implementation' ;
|
||||
}
|
||||
}
|
||||
|
||||
class Delegate {
|
||||
function thing() {
|
||||
return 'Delegate Implementation' ;
|
||||
}
|
||||
}
|
||||
|
||||
$a = new Delegator() ;
|
||||
print "{$a->operation()}\n" ;
|
||||
|
||||
$a->delegate = 'A delegate may be any object' ;
|
||||
print "{$a->operation()}\n" ;
|
||||
|
||||
$a->delegate = new Delegate() ;
|
||||
print "{$a->operation()}\n" ;
|
||||
Loading…
Add table
Add a link
Reference in a new issue