rgb192
asked on
know to go back to DocumentObject::getGroup
<?php
abstract class DomainObject {
private $group;
public function __construct() {
$this->group = static::getGroup();
}
public static function create() {
return new static();
}
static function getGroup() {
return "from default";
}
}
class User extends DomainObject {
}
class Document extends DomainObject {
static function getGroup() {
return "from document";
}
}
class SpreadSheet extends Document {
}
echo'<pre>';
$userCreate=User::create();
print_r($userCreate);
$spreadSheetCreate=SpreadSheet::create();
print_r($spreadSheetCreate);
echo'</pre>';
?>
how does
$spreadSheetCreate=SpreadS
know to go back to
DocumentObject::getGroup
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For better or worse, computer programming is a "precise science" requiring that we use the right names for variables and functions.
ASKER
sorry I meant
DomainObject::getGroup
not
DocumentObject::getGroup
go to different getGroup
$userCreate=User::create() ;
$spreadSheetCreate=SpreadS heet::crea te();
Is this example of late static binding?
DomainObject::getGroup
not
DocumentObject::getGroup
go to different getGroup
$userCreate=User::create()
$spreadSheetCreate=SpreadS
Through inheritance. The Spreadsheet class inherits Document's methods.
This includes the getGroup() method (which is overriden in the Document class).
Is this example of late static binding?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for examples about calling methods.