11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 7 • ADVANCED OOP FEATURESclass Contractor implements IEmployee, IDeveloper {...}As you can see, all three interfaces (IEmployee, IDeveloper, and IPillage) have been made availableto the employee, while only IEmployee and IDeveloper have been made available to the contractor.Abstract ClassesAn abstract class is a class that really isn’t supposed to ever be instantiated but instead serves as a baseclass to be inherited by other classes. For example, consider a class titled Media, intended to embody thecommon characteristics of various types of published materials such as newspapers, books, and CDs.Because the Media class doesn’t represent a real-life entity but is instead a generalized representation ofa range of similar entities, you’d never want to instantiate it directly. To ensure that this doesn’t happen,the class is deemed abstract. The various derived Media classes then inherit this abstract class, ensuringconformity among the child classes because all methods defined in that abstract class must beimplemented within the subclass.A class is declared abstract by prefacing the definition with the word abstract, like so:abstract class Class_Name{// insert attribute definitions here// insert method definitions here}Attempting to instantiate an abstract class results in the following error message:Fatal error: Cannot instantiate abstract class Employee in/www/book/chapter07/class.inc.php.Abstract classes ensure conformity because any classes derived from them must implement allabstract methods derived within the class. Attempting to forgo implementation of any abstract methoddefined in the class results in a fatal error.171

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

Saved successfully!

Ooh no, something went wrong!