Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

is getPlayLength(), getNumberOfPages() ever used?

Posted on 2014-03-23
4
Medium Priority
?
375 Views
Last Modified: 2014-03-23
<?php
class ShopProduct {
    public $numPages;
    public $playLength;
    public $title;
    public $producerMainName;
    public $producerFirstName;
    public $price;

    function __construct(   $title, $firstName,
                            $mainName, $price,
                            $numPages=0, $playLength=0 ) {
        $this->title             = $title;
        $this->producerFirstName = $firstName;
        $this->producerMainName  = $mainName;
        $this->price             = $price;
        $this->numPages          = $numPages;
        $this->playLength        = $playLength;
    }

    function getProducer() {
        return "{$this->producerFirstName}".
               " {$this->producerMainName}";
    }

    function getSummaryLine() {
        $base  = "$this->title ( {$this->producerMainName}, ";
        $base .= "{$this->producerFirstName} )";
        return $base;
    }
}

class CdProduct extends ShopProduct {

    function getPlayLength() {
        return $this->playLength;
    }

    function getSummaryLine() {
        $base  = "{$this->title} ( {$this->producerMainName}, ";
        $base .= "{$this->producerFirstName} )";
        $base .= ": playing time - {$this->playLength}";
        return $base;
    }
}

class BookProduct extends ShopProduct {
    function getNumberOfPages() {
        return $this->numPages;
    }

    function getSummaryLine() {
        $base  = "{$this->title} ( {$this->producerMainName}, ";
        $base .= "{$this->producerFirstName} )";
        $base .= ": page count - {$this->numPages}";
        return $base;
    }
}

$product1 = new CdProduct("cd1", "bob", "bobbleson", 4, null, 50 );
print $product1->getSummaryLine();
print "\n";

$product2 = new BookProduct("book1", "harry", "harrelson", 4, 30 );
print $product2->getSummaryLine();
print "\n";

?>

Open in new window



is getPlayLength(), getNumberOfPages() ever used?
0
Comment
Question by:rgb192
4 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 668 total points
ID: 39949104
In the posted code? No. But you could use from the external script:

$product2 = new BookProduct("book1", "harry", "harrelson", 4, 30 );
print $product2->getNumberOfPages();
print "\n";

Open in new window


I think that is only an example...
0
 
LVL 27

Assisted Solution

by:Cornelia Yoder
Cornelia Yoder earned 664 total points
ID: 39949105
Not in the script you show here.

But this whole script looks like a lot of functions that would be "included" in other scripts and used there.
0
 
LVL 35

Assisted Solution

by:Dan Craciun
Dan Craciun earned 668 total points
ID: 39949108
They are, in the declaration of your classes. They're getters.

On your code, they are not used on your 2 objects, but they are available.

HTH,
Dan
0
 

Author Closing Comment

by:rgb192
ID: 39949127
Getters to be used in external scripts.  Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question