首页 > 其他 > 详细

page39 类的访问权限控制

时间:2015-03-25 13:53:08      阅读:244      评论:0      收藏:0      [点我收藏+]
<?php
/**
 * Page37 Class
 * @authors haidong (admin@zhe700.net)
 * @date    2015-03-25 11:21:21
 * @version $Id$
 */

class ShopProduct{
    private $title;
    private $producerMainName;
    private $producerFirstName;
    protected $price;
    private $discount = 0;
    public function __construct($title,$producerMainName,$producerFirstName,$price){
        $this->title = $title;
        $this->producerMainName = $producerMainName;
        $this->producerFirstName = $producerFirstName;
        $this->price = $price;
    }
    public function getProducerMainName(){
        return $this->producerMainName;
    }
    public function getProducerFirstName(){
        return $this->producerFirstName;
    }
    public function getDiscount(){
        return $this->discount;
    }
    public function serDiscount($discount){
        return $this->discount = $discount;
    }
    public function getPrice(){
        return ($this->price - $this->discount);
    }
    public function getProducer(){
        return "{$this->producerFirstName} {$this->producerMainName}";
    }
    public function getSummaryLine(){
        return "{$this->title} ({$this->producerFirstName} {$this->producerMainName})";
    }
}
class CdProduct extends ShopProduct{
    private $playLength;
    public function __construct($title,$producerMainName,$producerMainName,$price,$playLength){
        parent::__construct($title,$producerMainName,$producerMainName,$price);
        $this->playLength = $playLength;
    }
    public function getPlayLength(){
        return $this->playLength;
    }
    public function getSummaryLine(){
        $base = parent::getSummaryLine();
        $base .= "play time ({$this->playLength})";
        return $base;
    }
}
class BookProduct extends ShopProduct{
    private $numPages;
    public function __construct($title,$producerMainName,$producerMainName,$price,$numPages){
        parent::__construct($title,$producerMainName,$producerMainName,$price);
        $this->numPages = $numPages;
    }
    public function getNumPages(){
        return $this->numPages;
    }
    public function getSummaryLine(){
        $base = parent::getSummaryLine();
        $base .= "total pages ({$this->numPages})";
        return $base;
    }
}
$cd = new CdProduct(‘CD‘,‘John‘,‘Smith‘,79,90);
echo $cd->getSummaryLine();
$book = new BookProduct(‘Book‘,‘Bob‘,‘zhang‘,49,360);
echo $book->getSummaryLine();

加入了权限的控制

page39 类的访问权限控制

原文:http://www.cnblogs.com/haidong/p/4365409.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!