HTML and CSS Reference
In-Depth Information
public function drink( )
{
$this->drinks[] = 'coffee';
}
public function wish( )
{
$wish_index = mt_rand(0, count($this->_wishes)-1);
return $this->_wishes[$wish_index];
}
}
class Phil extends Person
{
public function drink( )
{
$this->drinks[] = 'tea';
}
}
the Person class sets up properties that are universal, as well as a sleep() method that all classes (people)
extending the class will share.
it then defines an abstract method, drink() . Because all people drink, but not all people drink the same
beverages, this method needs to be required, but not defined; that's where abstract classes are powerful.
now when the Jason and Phil classes are defined, the groundwork is already laid—no extra code is required to
allow for sleeping—so the code to finish these classes is extremely simple.
it's also worth noting that classes that extend an abstract class are not limited by the provided methods and
method stubs; additional properties and methods can be declared as needed. For example, the Jason class
includes a private property— $_wishes —and an additional method called wish() . 3
Creating the Abstract Controller Class
The Controller class is very straightforward: it needs to check that required data was passed in and define method
stubs for generating a page title and parsing the view.
Create a new file called class.controller.inc.php and save it in the system/core/ subdirectory. Inside, paste
the following code:
<?php
/**
* An abstract class that lays the groundwork for all controllers
*
* @author Jason Lengstorf <jason@lengstorf.com>
* @author Phil Leggetter <phil@leggetter.co.uk>
*/
3 Phildoesn'twish.Heplans.
 
 
Search WWH ::




Custom Search