Introduction to Abstract Classes and Methods
Explore the concept of abstract classes and methods in PHP to ensure child classes implement specific methods. Understand how to declare abstract classes with abstract and non-abstract methods, and why they are essential when method details are unknown at the parent level. Gain skills to properly use abstraction in PHP OOP to design flexible and maintainable code structures.
We'll cover the following...
We use abstract classes when we want to commit the programmer to write a certain class method, but we only know the name of the method without any details of how it should be written.
For example, circles, rectangles, and octagons may look different but are all 2-D shapes. This means they all have an area and a circumference. It makes sense, then, to group the code that they have in common into one parent class. In this parent class, we’ll have the area and circumference properties, and we may also have a method that calculates the area (this could be a problem ...