25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

126 ” Object Oriented Programming in <strong>PHP</strong><br />

don’t actually have a body—that’s one of the requirements of abstract classes—and<br />

how the class itself must be declared as abstract in order for the compiler to satisfy<br />

the parser’s syntactic requirements. We then extend DataStore_Adapter into<br />

PDO_DataStore_Adapter, which is no longer abstract because we have now provided<br />

a body for both insert() and update().<br />

Interfaces<br />

Interfaces, on the other hand, are used to specify an API that a class must implement.<br />

This allows you to create a common “contract” that your classes must implement in<br />

order to satisfy certain logical requirements—for example, you could use interfaces<br />

to abstract the concept of database provider into a common API that could then be<br />

implemented by a series of classes that interface to different DBMSs.<br />

Interface methods contain no body:<br />

interface DataStore_Adapter {<br />

public function insert();<br />

public function update();<br />

public function save();<br />

public function newRecord($name = null);<br />

}<br />

class PDO_DataStore_Adapter implements DataStore_Adapter {<br />

public function insert()<br />

{<br />

// ...<br />

}<br />

public function update()<br />

{<br />

// ...<br />

}<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)<br />

public function save()<br />

{<br />

// ...<br />

}<br />

public function newRecord($name = null)<br />

{

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!