Abstract Classes

In Chapter 10 we saw that if a derived class does not implement all the methods of an interface, then it must be declared abstract. Let's push this concept to the extreme and see what a completely abstract class might look like. Listing 11-1 shows the definition of such a class.

Listing 11-1. The definition of the abstract class Bird
❶abstract class Bird{
  protected $plumage;
  protected $migratory;
  abstract public function __construct();
  abstract public function fly();
  abstract public function sing();
  abstract public function eat();
  abstract public function setPlumage($plumage);
  abstract public function getPlumage();
  abstract public function setMigratory($migratory);
  abstract public function getMigratory();
}

As we saw in ...

Get Object-Oriented PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.