Such a feature is available as of PHP 5. Consider this example:
interface IEmployee {...}
interface IDeveloper {...}
interface IPillage {...}
CHAPTER 7 ?– ADVANCED OOP FEATURES 207
class Employee implements IEmployee, IDeveloper, iPillage {
...
}
class Contractor implements IEmployee, IDeveloper {
...
}
?>
As you can see, all three interfaces (IEmployee, IDeveloper, and IPillage) have been
made available to the employee, while only IEmployee and IDeveloper have been
made available to the contractor.
Abstract Classes
An abstract class is a class that really isn??™t supposed to ever be instantiated but instead
serves as a base class to be inherited by other classes. For example, consider a class
titled Media, intended to embody the common 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 of a
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, ensuring conformity among the child classes because all
methods defined in that abstract class must be implemented 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.
Pages:
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285