As a WordPress developer, you’re always looking for ways to better reuse your code between projects. Your time is valuable and you don’t want to reinvent the wheel each time you start a new project. Object-oriented programming can help you with that. In a previous post, I covered why you should learn it. Now it’s time to take things further by going over the main feature for code reuse. You’ve probably heard about it before. It’s called “inheritance“. Inheritance, what’s that? Inheritance is about maximizing the code reuse between your classes. It allows you to create a hierarchy between your classes. That hierarchy creates a “is-a” relationship between your classes. That’s why a lot of examples follow the formula: class Car extends Vehicle (Car is a Vehicle) class Dog extends Animal (Dog is an Animal) They aren’t practical examples, but they highlight that relationship. The take away from those examples is that you need to learn to see the relationship between your classes. Once that happens, you’ll be able to leverage inheritance to create reusable code for your projects. Visibility revisited When I covered encapsulation, I mentioned three possible access levels for properties and
Share This