Page 244 - Beginning PHP 5.3
P. 244
Part II: Learning the Language
public function setScreenSize( $screenSize ) {
$this- > _screenSize = $screenSize;
}
public function addStock( $numItems ) {
$this- > _stockLevel += $numItems;
}
public function sellItem() {
if ( $this- > _stockLevel > 0 ) {
$this- > _stockLevel--;
return true;
} else {
return false;
}
}
public function getStockLevel() {
return $this- > _stockLevel;
}
}
class TennisBall implements Sellable {
private $_color;
private $_ballsLeft;
public function getColor() {
return $this- > _color;
}
public function setColor( $color ) {
$this- > _color = $color;
}
public function addStock( $numItems ) {
$this- > _ballsLeft += $numItems;
}
public function sellItem() {
if ( $this- > _ballsLeft > 0 ) {
$this- > _ballsLeft--;
return true;
} else {
return false;
}
}
public function getStockLevel() {
return $this- > _ballsLeft;
}
}
class StoreManager {
private $_productList = array();
206
9/21/09 9:03:45 AM
c08.indd 206
c08.indd 206 9/21/09 9:03:45 AM