Page 245 - Beginning PHP 5.3
P. 245

Chapter 8: Objects


                               public function addProduct( Sellable $product ) {
                                 $this- > _productList[] = $product;
                               }

                               public function stockUp() {
                                 foreach ( $this- > _productList as $product ) {
                                   $product- > addStock( 100 );
                                 }
                               }
                             }

                             $tv = new Television;
                             $tv- > setScreenSize( 42 );
                             $ball = new TennisBall;
                             $ball- > setColor( “yellow” );
                             $manager = new StoreManager();
                             $manager- > addProduct( $tv );
                             $manager- > addProduct( $ball );
                             $manager- > stockUp();
                             echo “ < p > There are “. $tv- > getStockLevel() . “ “ . $tv- > getScreenSize();
                             echo “-inch televisions and “ . $ball- > getStockLevel() . “ “ .
                             $ball- > getColor();
                             echo “ tennis balls in stock. < /p > ”;
                             echo “ < p > Selling a television... < /p > ”;
                             $tv- > sellItem();
                             echo “ < p > Selling two tennis balls... < /p > ”;
                             $ball- > sellItem();
                             $ball- > sellItem();
                             echo “ < p > There are now “. $tv- > getStockLevel() . “ “ . $tv- > getScreenSize();
                             echo “-inch televisions and “ . $ball- > getStockLevel() . “ “ .
                             $ball- > getColor();
                             echo “ tennis balls in stock. < /p > ”;
                             ? >

                                <  /body >


                               < /html >




















                                      Figure 8 - 7
                                                                                                         207





                                                                                                      9/21/09   9:03:45 AM
          c08.indd   207
          c08.indd   207                                                                              9/21/09   9:03:45 AM
   240   241   242   243   244   245   246   247   248   249   250