看了刀客的文章有个地方不是很明白!
时间:2008-03-26
来源:互联网
复制PHP内容到剪贴板
模版设计模式的模版部分.
<?
abstract class LoanAccount
{
//利息,本金
protected $interest,$fund;
public function calculateInterest()
{
// 取得利率
$this->interest = getInterestRate();
//用于计算利息的算法:本金*利率,但是利率的算法实现并没有在这个类中实现
$this->interest=$this->getFund()*$this->getInterestRate();
return $this->interest;
}
private function getFund(){
return $this->fund;
}
//… …
/*不同的存款类型有不同的利率, 因此,不在这个父类中实现利率的计算方法,
* 而将它推迟到子类中实现
*/
protected abstract function getInterestRate();
}
?>
其中PHP代码:
3-4 LoanAccount.php<br>模版设计模式的模版部分.
<?
abstract class LoanAccount
{
//利息,本金
protected $interest,$fund;
public function calculateInterest()
{
// 取得利率
$this->interest = getInterestRate();
//用于计算利息的算法:本金*利率,但是利率的算法实现并没有在这个类中实现
$this->interest=$this->getFund()*$this->getInterestRate();
return $this->interest;
}
private function getFund(){
return $this->fund;
}
//… …
/*不同的存款类型有不同的利率, 因此,不在这个父类中实现利率的计算方法,
* 而将它推迟到子类中实现
*/
protected abstract function getInterestRate();
}
?>
// 取得利率
$this->interest = getInterestRate();
为什么不是这样写呢? $this->interest = $this->getInterestRate(); 少了个$this->。
而这里却用到了$this->:
$this->interest=$this->getFund()*$this->getInterestRate();
请问在抽象类里调用本类的抽象方法,可以不用"$this-> " 吗?
作者: 黄山狼 发布时间: 2008-03-25
帮你顶下
再留个名
http://wolf.rorchina.net/ 狼盟编程论坛
http://bbs.rorchina.net/ RORCHINA中国社区门户
http://club.unix5.com/ UNIX开源世纪
再留个名
http://wolf.rorchina.net/ 狼盟编程论坛
http://bbs.rorchina.net/ RORCHINA中国社区门户
http://club.unix5.com/ UNIX开源世纪
作者: 会飞的猪 发布时间: 2008-03-25
测试一下不就知道了!
作者: yiqing666 发布时间: 2008-04-16
不要看了,哪个例子没有什么实际的意思
作者: water6000 发布时间: 2008-04-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28