zoukankan      html  css  js  c++  java
  • page39 类的访问权限控制

    <?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();

    加入了权限的控制

  • 相关阅读:
    SDUTOJ 2775 小P的故事——奇妙的饭卡
    STL vector的构造函数和析构函数(2)
    Spark调研笔记第6篇
    【精】iOS GCD 具体解释
    爆头
    uva 624 CD
    一站式学习Wireshark(转载)
    TCP的状态 (SYN, FIN, ACK, PSH, RST, URG)
    loadrunner两个函数:取参数长度和时间戳函数
    自行控制loadrunner的socket协议性能测试 (转)
  • 原文地址:https://www.cnblogs.com/haidong/p/4365409.html
Copyright © 2011-2022 走看看