An object has both characteristics and behavior. It is built from a blueprint. To help you grasp the concept, let’s relate software objects to physical, real world objects. We are going to talk about homes in a new subdivision. You’ll see how the concept of homes (objects) can be translated into software objects and OOP.
Imagine that you want to buy a new home in a new development. Here in the US, we call this a residential subdivision. You go to the developer, i.e. the company that is building this subdivision. You select the plan (or model) for the home that you want to build. Imagine that there will be 300 homes in this subdivision and only 4 plans (models). That means your plan will be duplicated throughout the neighborhood. There could be 90 or more homes that look just like yours.
The homes are built to a set of blueprints that the architect designs. It defines how to build the home including all the details that are needed for the craftsman to build your home. Can you picture it in your mind? The blueprints detail the foundation, framing, trusses, and exterior components. Then they detail out the interior including kitchen cabinet placement, fireplace, bathroom components, etc. The blueprints define the home, which is an object.
Picture yourself in the completed subdivision. Imagine that you are at your home and across the street is the exact same home. These two homes are two separate objects, but they are made from the same blueprint. But you will change some of the characteristics to fit your needs, such as the countertops, carpeting, colors, etc. Your home has behaviors. When you click on the garage door opener, the door goes up. Putting the key in the door lock will unlock the door. Turning the handle, the door opens.
Let’s relate this example to software objects. Objects have:
- Characteristics (attributes) – in PHP, we call them properties
- Behaviors (work) – in PHP, we call them methods (the keyword is
- Blueprint – defines how to build the object – a
classis used in PHP
From one blueprint (class), you can create multiple objects. Each object is different, just like in the example above.
Don’t repeat yourself. Don’t repeat yourself. Don’t repeat yourself.
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