3.12. Abstract Methods and Classes

When designing class hierarchies, you might want to partially leave certain methods for inheriting classes to implement. For example, say you have the class hierarchy shown in Figure 3.2.

Figure 3.2. Class hierarchy.

It might make sense to implement setCenter($x, $y) in class Shape and leave the implementation of the draw() methods to the concrete classes Square and Circle. You would have to declare the draw() method as an abstract method so that PHP knows you are intentionally not implementing it in class Shape. The class Shape would then be called an abstract class, meaning that it's not a class with complete ...

Get PHP 5 Power Programming 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.