cvs: ZendEngine2 /RFCs 004.txt
| From: | Sebastian Bergmann | Date: | Thu, 06 Jun 2002 21:13:40 +0000 |
| Subject: | cvs: ZendEngine2 /RFCs 004.txt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-155@lists.php.net to get a copy of this message | ||
sebastian Thu Jun 6 17:13:40 2002 EDT
Added files:
/ZendEngine2/RFCs 004.txt
Log:
Add RFC on delegation.
Index: ZendEngine2/RFCs/004.txt
+++ ZendEngine2/RFCs/004.txt
Title: Delegation
(a/k/a. Object-Based Inheritance)
Version: $Revision: 1.1 $
Status: draft
Maintainer: Sebastian Bergmann <sb@sebastian-bergmann.de>
Dynamic Delegation
Syntax / Example
<?php
class aDelegatee {
function doSomething() {
echo 'hubu';
}
}
class anotherDelegatee {
function doSomething() {
echo 'tubu';
}
}
class Foo {
delegatee $bar;
function setDelegatee($delegatee) {
$this->delegatee = $delegatee;
}
}
$foo = new Foo;
$foo->setDelegatee(new aDelegatee);
$foo->doSomething(); /* prints "hubu" */
$foo->setDelegatee(new anotherDelegatee);
$foo->doSomething(); /* prints "tubu" */
?>
Semantics / Synopsis
The "Foo" class may use all methods available in "$bar" as if they
where locally defined or inherited from a superclass. The essential
difference is that by assigning another object to "$bar" it is
possible to dynamically switch between different implementations for
these methods.
Fixed Delegation
Syntax / Example
<?php
class aDelegatee {
function doSomething() {
echo 'hubu';
}
}
class Foo {
final delegatee $bar = new aDelegatee;
}
$foo = new Foo;
$foo->doSomething(); /* prints "hubu" */
?>
Semantics / Synopsis
The "Foo" class may use all methods available in "$bar" as if they
where locally defined or inherited from a superclass. The difference
to the dynamic delegation is that once the delegatee object is set,
it cannot be changed.