And actually there is one last thing worth learning now about OOP. You can make new classes that inherit from another class. Check this code:
class BlogEntry extends Entry
public function exageratePageCount()
echo $this->pageCount + 20;
Notice how the "pageCount" property is not defined in the BlogEntry class. It's because it's inherited from the Entry class. Now let’s rebuild $article 1, but from the BlogEntry class/template instead, and execute this new method:
Now the browser reads that it has 120 pages. The idea is so damn simple: objects instantiated/generated from the BlogEntry class have access to all the properties and methods from the parent class, Entry. Therefore you can write a reduced amount of code when you want to create similar classes. point blank period. Again, don’t worry too much about inheritance yet. It’s a feature you’ll use a lot, but a very simple one to code up and make use of. You’ll know when you need to use it to not have to write redundant code.
Super final note on OOP: visualize all this OOP stuff as simulating a world in programming. The idea is to make coding more human-like, more like the real world. I.e. classes can have children and parent classes, just like humans can have real children and real parents. Later on you’ll learn even more ways objects can work together, just as objects and organisms in the real world can. But I’m not covering that in this book. Look out for the terms “aggregation” and “composition”--they are techniques to make objects work together to create re-usable code and efficient solutions. For now inheritance is the code reuse technique we’ll leave you on. Don’t plan on abusing it ;).