Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Object-Oriented PHP Basics!
You have completed Object-Oriented PHP Basics!
Preview
We’ll take the basic programming concepts you already know and show you how to think about software in terms of objects.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
For many PHP programmers, object oriented
programming is an intimidating concept,
0:00
because it introduces new syntax and
seemingly complex terminology.
0:05
At a glance, object oriented programming
can appear to be far more complex
0:10
than simple procedural or inline code.
0:15
However, this doesn't have to be the case.
0:18
As you'll see, object oriented programming
0:21
is actually similar to the way
we perceive the real world.
0:24
That means an object oriented approach
0:28
can help you visualize the solution
to a problem more easily.
0:30
Object oriented programming or OOP for
short, is a style of coding that
0:34
allows developers to group
similar tasks into containers.
0:39
In php,
containers are defined using classes.
0:43
A class contains all the functions and
variables that define an object.
0:47
These functions are called methods and
the variables are called properties.
0:53
[SOUND] To give you a real world example
of this, let's take a look at a house.
0:56
A house defined by a blueprint
which shows the layout, rooms and
1:01
exact design for the house.
1:06
Each house has attributes like walls,
a roof, windows and doors.
1:09
They also have actions such as open
the door or turn on the light.
1:15
The blueprint could be the class.
1:21
It's not a house itself, but
it describes how a house should be built,
1:23
with relationships between the different
parts of the house clearly defined and
1:27
planned out.
1:31
The walls, roof, windows,
and doors are properties.
1:33
While opening the door and
turning on the lights are methods.
1:37
As I just mentioned
a blueprint is not a house.
1:42
But you use a blueprint
to build new houses.
1:45
Each time a new house is built,
we create a new object, a house object.
1:49
If our blueprint is a class named house,
1:55
we can build an entire subdivision
of houses based on this blueprint.
1:58
This is called instantiating an object or
creating an instance of an object.
2:03
Each house object shares the properties
and methods of the house class.
2:10
But the individual values for
each house may be different.
2:14
My house may have brown walls and
a red roof.
2:19
While your house could have
white walls and a blue roof.
2:23
Grouping code into these containers,
or classes, can make it easier to
2:28
follow the tenet, don't repeat yourself,
or D-R-Y, dry for short.
2:32
One of the major benefits in
following the DRY principle is that,
2:37
if a piece of information
changes in your program,
2:41
you usually only need to
change the code in one place.
2:44
One of the biggest nightmares for
developers,
2:48
is maintaining code where data
is declared over and over again.
2:50
If something goes wrong tracking down
the error can be like looking for
2:56
a needle in a haystack.
3:00
As you hunt for duplicated data and
3:01
functionality, sometimes finding
that needle can be painful.
3:03
This course is designed
to teach you the why and
3:08
how of object oriented programming.
3:11
Before we jump feet first into the how,
3:14
let's get a little more
familiar with the why.
3:16
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up