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.

CHAPTER 7 • ADVANCED OOP FEATURESwww.it-ebooks.infoThis interface is then implemented for use by the Executive class:class Executive extends Employee implements IPillage{private $totalStockOptions;function emptyBankAccount(){echo "Call CFO and ask to transfer funds to Swiss bank account.";}}function burnDocuments(){echo "Torch the office suite.";}Because pillaging should be carried out at all levels of the company, you can implement the sameinterface by the Assistant class:class Assistant extends Employee implements IPillage{function takeMemo() {echo "Taking memo...";}function emptyBankAccount(){echo "Go on shopping spree with office credit card.";}}function burnDocuments(){echo "Start small fire in the trash can.";}As you can see, interfaces are particularly useful because, although they define the number andname of the methods required for some behavior to occur, they acknowledge the fact that differentclasses might require different ways of carrying out those methods. In this example, the Assistant classburns documents by setting them on fire in a trash can, while the Executive class does so throughsomewhat more aggressive means (setting the executive’s office on fire).Implementing Multiple InterfacesOf course, it wouldn’t be fair to allow outside contractors to pillage the company; after all, it was uponthe backs of the full-time employees that the organization was built. That said, how can you provideemployees with the ability to both do their jobs and pillage the company, while limiting contractorssolely to the tasks required of them? The solution is to break these tasks down into several tasks and thenimplement multiple interfaces as necessary. Such a feature is available as of <strong>PHP</strong> 5. Consider thisexample:170

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

Saved successfully!

Ooh no, something went wrong!