Unlock your potential with a Pro Membership
Here is where you propel your career forward. Come join us today. Learn more.
Hiding Away the Complexity
Lab: Introduction to PHP Object-Oriented Programming (OOP) for WordPress
Video Runtime: 22:40
Part of OOP is the ability to hide away complexity from the outside world. The object controls the sequence for the work to be done. It only exposes what it is needed for the application to work with the object.
For example, let’s relate this difficult concept to a car. When you start your car, the car handles all the tasks to start the car. It handles the air and gas mixtures, pistons, spark plugs, and circuits. You don’t have to manually sequence through each of those tasks yourself to start that car. No, you just push the button or turn the key. The car takes over from there and executes each of the steps for you.
Imagine for a moment if you had to do all of those tasks yourself…in the right order and timing. That’s too complex and error-prone. Instead, the complexity is hidden away and an interface is exposed for you to start the car.
It’s same in OOP. If you were building a car blueprint, you’d have a public function called “start.” Then that function (method) would call each of the tasks to get the car to start for you. Each of the methods then is hidden away. You can’t access them.
PHP provides you with visibility keywords that emulate what I just explained:
public
means the application can call the method or set/get the propertyprotected
means only the object has access and can work with the method or propertyprivate
is the same asprotected
except that another class blueprint can’t extend it (inheritance)
Let’s take these concepts and discuss them more deeply. Then in this episode, you’ll modify the User
class and see how this works.
Hands off the keyboard. Web development starts by thinking first, then planning it out, and then coding it.
Episodes
Total Lab Runtime: 03:04:55
- 1 Lab Introductionfree 08:27
- 2 What is Object-Oriented Programming (OOP)?free 14:14
- 3 What is an object?free 13:30
- 4 Meet the Class Blueprintpro 04:53
- 5 Creating an Objectpro 07:57
- 6 Defining Characteristicspro 10:54
- 7 Putting the Object to Workpro 13:56
- 8 Hiding Away the Complexitypro 22:40
- 9 Working within the Object with $thispro 15:41
- 10 Internal Control of Object Creationpro 15:07
- 11 Class Constantspro 08:58
- 12 Class Staticpro 17:49
- 13 What OOP is Notpro 19:11
- 14 Practical Examplespro 04:52
- 15 Wrap it Uppro 06:46