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

Inheritance

Оглавление

Recall Mindi’s tattoos, specifically the tattoo on her back? The tattoo on her back was described as protected in PHP terms meaning that it was visible within the Mindi class and to classes that extended the Mindi class. To inherit in PHP5, you should use the keyword extends in the class definition.


Inheritance passes "knowledge" down. It is a structured way of extending code and functionality into new programs and packages. Classes are created in hierarchies and inheritance allows the structure and methods in one class to be passed down the hierarchy. That means less programming is required when adding functions to complex systems. If a step is added at the bottom of a hierarchy, then only the processing and data associated with that unique step needs to be added. Everything else about that step is inherited. The ability to reuse existing objects is considered a major advantage of object oriented programming.

PHP This! A Beginners Guide to Learning Object Oriented  PHP

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