文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>php类学习 - Extends(扩展)

php类学习 - Extends(扩展)

时间:2007-07-06  来源:windlike

class Counter{
  var $count = 0;
  var $startPoint = 0;  
  //method
  function startCountAt($i){
    $this->count = $i;
    $this->startPoint = $i;
  }
  
  function increment(){
    $this->count++;
  }
  
  function reset(){
    $this->count = $this->startPoint;
  }
  function showValue(){
    echo $this->count;
  }
}
class BottleCounter extends Counter
{
  function addCase()
  {
    $this->count += 12;
  }
  function caseCount()
  {
    return ceil($this->count / 12);
  }
  function BottleCounter($startCount)
  {
    $this->count = $startCount;
  }
}
class CanCounter extends BottleCounter
{
  function volumeDiscount($var)
  {
    if($var->count > 24)
    {
      return 0.95;
    }else{
      return 1.0;
    }
  }
}
/*
$count = new Counter;
$count->startCountAt(10);
echo $count->count;
$count->increment();
echo $count->count;
$count->showValue();
$count->reset();
$count->showValue();
*/
$bottles = new BottleCounter(10);
$cans = new CanCounter(25);
echo $bottleDiscountFactor = volumeDiscount($bottles);
echo $canDiscountFactor = volumeDiscount($cans);


相关阅读 更多 +
排行榜 更多 +
jojo的奇妙冒险手机版下载

jojo的奇妙冒险手机版下载

飞行射击 下载
雪糕工厂 v9.87.13.02 安卓版

雪糕工厂 v9.87.13.02 安卓版

休闲益智 下载
雪糕工厂 v9.87.13.02 安卓版

雪糕工厂 v9.87.13.02 安卓版

休闲益智 下载