WHAT'S HOT
Prev | Current Page 362 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"


abstract class ZFiA_Person A
{
protected $_firstName;
protected $_lastName;
public __construct($firstName, $lastName) B
{
$this->_firstName = $firstName;
$this->_lastName = $lastName;
}
abstract public function fullName(); C
}
A Abstract keyword in class definition
B Standard member function
C Abstract function is not defined in this class
As ZFiA_Person is now declared as an abstract class, it can no longer be instantiated directly using new; it
must be extended the child class instantiated. As the function fullName() is defined as abstract, all child classes
(that are not themselves declared as abstract) must provide an implementation of this function. We can
therefore provide an implementation of ZFiA_Author in listing 17.6.
Listing 17.6 An Abstract class contains undefined functions that must be implemented by child classes.
class ZFiA_Author extends ZFiA_Person
{
public function fullName()
{
$name = $this->_firstName . ' ' . $this->lastName;
$name .= ', Author';
return $name;
}
}
As you can see, the ZFiA_Author class provides a specific implementation of fullName() that is not
appropriate to any other child class of ZFiA_Person.
One limitation of the PHP object model is that a class may only inherit from one parent class. There are
lots of good reasons for this, but it does mean that another mechanism is required to enable a class to conform
to more than one ???template???.


Pages:
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
meble drewniane ubezpieczenia komunikacyjne klimatyzacja stalowa wola 2 1 hostel krakow