note 100976 added to language.oop5.decon
| From: | lbergman at considerateconsultancy dot com | Date: | Thu, 18 Nov 2010 09:01:08 +0000 |
| Subject: | note 100976 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174143@lists.php.net to get a copy of this message | ||
Multiple constructors can be simulated in a fashion using Inversion of Control. Inversion of Control
means that the callee is deciding how to implement the information provided by the caller. That
greatly simplifies code as the caller does not have to know anything from the callee. They have to
have an agreement about data transfer. That is all.
To accomplish that the caller provides an array of data. What the callee is doing with the data is
not of interest of the caller. That is why the caller is providing the data in a standard format.
Now the callee can decide upon the information in the array how to process the data. An example:
The caller is requesting like this:
$obj = new Template($arVals);
The class Template has this constructor:
function __construct($arVals){
if(is_null($arVals) || !is_array($arVals)){
_conDef();
}
if(count($arVals) == 1){
_conName($arVals[0]);
}else if(count($arVals) == 2){
_conPage2($arVals[0],$arVals[1]);
}else{
_conDef();
}
$this->setName($name);
}
function _conDef(){
$this->setName("base");
$this->setStartPage("templates/base");
}
function __conName($name){
$this->setName($name);
}
function __conPage2($name, $page){
$this->setName($name);
$this->setStartPage($page);
}
How the class Template is handling the information has become independent of the caller.
----
Server IP: 69.147.83.197
Probable Submitter: 83.119.96.49
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- https://master.php.net/note/edit/100976
Del: integrated -- https://master.php.net/note/delete/100976/integrated
Del: useless -- https://master.php.net/note/delete/100976/useless
Del: bad code -- https://master.php.net/note/delete/100976/bad+code
Del: spam -- https://master.php.net/note/delete/100976/spam
Del: non-english -- https://master.php.net/note/delete/100976/non-english
Del: in docs -- https://master.php.net/note/delete/100976/in+docs
Del: other reasons-- https://master.php.net/note/delete/100976
Reject -- https://master.php.net/note/reject/100976
Search -- https://master.php.net/manage/user-notes.php