例2,php抽象类的例子
title = $title; $this->firstname = $firstname; $this->lastname = $mainname; $this->salary = $salary; } public function firstname() {
return $this->firstname; } public function getlastname() {
return $this->lastname; } public function setratio( $num ) {
$this->ratio=$num; } public function getratio() {
return $this->ratio; } public function gettitle() { return $this->title; } public function getsalary() {
return ($this->salary - $this->ratio); } public function getfullname() {
return {$this->firstname} . {$this->lastname}; } function getsummaryline() {
$base = $this->title ( $this->lastname, ; $base .= $this->firstname ); return $base; }}//定义抽象类
abstract class employeewriter { abstract static function write( employee $shopproduct );}class textemployeewriter extends employeewriter {
static function write( employee $shopemployee ) { $str = {$shopemployee->gettitle()}: ; $str .= $shopemployee->getfullname(); $str .= ({$shopemployee->getsalary()})\n; print $str; }}$developer1 = new employee(a, a1, a2, 5.99 );
textemployeewriter::write( $developer1 );?>
复制代码