HTML and CSS Reference
In-Depth Information
What are aBStraCt CLaSSeS?
Classes defined as abstract may not be instantiated, and any class that contains at least one abstract
method must also be abstract. Methods defined as abstract simply declare the method's signature—
they cannot define the implementation.
When inheriting from an abstract class, all methods marked abstract in the parent's class declaration
must be defined by the child[.]
—From the php manual entry on class abstraction 2
What this means is that an abstract class allows developers to create classes that act as a kind of template for
other classes while also providing common functionality. Because an abstract class can't be directly instantiated,
method “stubs” can be created, which require child classes to declare those methods and provide functionality
for them.
as a simple example, an abstract class might define a person. all people sleep and drink, so the abstract class
should define those methods. Because sleeping is virtually the same for all people, that can be defined within the
class. however, not all people drink the same things; that action should be defined as a stub to be declared in
child classes.
here's what that simple example might look like in real code:
abstract class Person
{
public $rest = 0,
$drinks = array();
public function sleep( )
{
++$rest;
}
abstract public function drink( );
}
class Jason extends Person
{
private $_wishes = array(
'a little bit taller',
'a baller',
'a girl who looks good',
'a rabbit in a hat',
'a bat',
'a \'64 Impala',
);
http://us3.php.net/manual/en/language.oop5.abstract.php .
2
 
Search WWH ::




Custom Search