Prev | Current Page 272 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

";
}
function burnDocuments()
{
echo "Torch the office suite.";
}
}
206 CHAPTER 7 ?–  ADVANCED OOP FEATURES
Because pillaging should be carried out at all levels of the company, you can
implement the same interface 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 and name of the methods required for some behavior to occur, they acknowledge
the fact that different classes might require different ways of carrying out those
methods. In this example, the Assistant class burns documents by setting them on fire in
a trash can, while the Executive class does so through somewhat more aggressive means
(setting the executive??™s office on fire).
Implementing Multiple Interfaces
Of course, it wouldn??™t be fair to allow outside contractors to pillage the company; after all,
it was upon the backs of the full-time employees that the organization was built. That
said, how can you provide employees with the ability to both do their jobs and pillage
the company, while limiting contractors solely to the tasks required of them? The
solution is to break these tasks down into several tasks and then implement multiple
interfaces as necessary.


Pages:
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284