Читать книгу PHP This! A Beginners Guide to Learning Object Oriented PHP - Michelle Gosney - Страница 10

Method Overriding

Оглавление

Method overriding is when the function of base class is re-defined with the same name, function signature and access modifier (either public or protected) of the derived class.

The reason to override a method is to provide additional functionality over and above what has been defined in the base class. Imagine that you have a class by the name of Beverage from which you derive two child classes, Martini and Scotch. The Beverage class has methods defined to stir, mix, etc, but each of the specialized classes Martini and Scotch will have its own style of mixing and stirring and hence would need to override the stir and mix functionality.

Lets look at an example with Beverage:


PHP This! A Beginners Guide to Learning Object Oriented  PHP

Подняться наверх