Created
March 5, 2015 10:33
-
-
Save fimak/89d01b24f7f7a835153e to your computer and use it in GitHub Desktop.
PHP Delegate pattern. Object instead of performing one of its stated tasks, delegates that task to an associated helper object. It helps us to inherit 2 methods from 2 different classes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A | |
{ | |
public function aFunc() | |
{ | |
echo __CLASS__; | |
} | |
} | |
class B | |
{ | |
public function bFunc() | |
{ | |
echo __CLASS__; | |
} | |
} | |
class C | |
{ | |
private $_a; | |
private $_b; | |
public function __construct() | |
{ | |
$this->_a = new A(); | |
$this->_b = new B(); | |
} | |
public function aFunc() | |
{ | |
$this->_a->aFunc(); | |
} | |
public function bFunc() | |
{ | |
$this->_b->bFunc(); | |
} | |
public function cFunc() | |
{ | |
echo __CLASS__; | |
} | |
} | |
$cObj = new C(); | |
$cObj->aFunc(); | |
$cObj->bFunc(); | |
$cObj->cFunc(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment