Beginning Object Oriented Programming in PHP
Sample of the pdf document :
Introduction
Object-Oriented Programming tutorials are generally bogged down with programming
theory and large, metaphysical words such as encapsulation, inheritance and
abstraction. They attempt to explain things by comparing code samples to microwaves
or automobiles which only serves to confuse the reader more.
But even when all the hype and mystique that surrounds Object-Oriented Programming
(OOP) has been stripped away, you'll find it is indeed a good thing. I won't list reasons
why; this isn't another cookie-cutter tutorial only serving to confuse you. Instead we'll
explore OOP in a way that'll start you on the fast track to polished OOP skills. As you
grow in confidence with your OOP skills and begin to use them more in your projects,
you'll most likely form your own list of benefits.
The Magic Box (Objects)
Imagine a box. It can be any type of box you want... a small jewelery box, a large
crate, wooden, plastic, tall and thin, Short and wide...
Next, imagine yourself placing something inside the box... a rock, a million dollars, your
younger sibling...
Now wouldn't it be convenient if we could walk up to the box and just ask it to tell us
what's inside instead of opening it ourselves? Actually, we can!
<?php
$mybox = new Box("Jack");
echo $mybox->get_whats_inside();
?>
Here the variable $mybox represents our self-aware box, which is also known as an
object, which will be built by new--the world's smallest engineering and construction
team! We also want to place Jack inside the box when it is built. When we want to ask
the box it's contents, we'll apply a special function to $mybox, get_whats_inside().
But the code won't run quite yet, though; we haven't supplied new with the directions
for him and his team to construct our box and PHP doesn't know what the function
get_whats_inside() is supposed to do.
Classes
A class is technically defined as a representation of an abstract data type. In laymen's
term, a class is a blueprint from which new will construct our box. It's made up of
variables and functions which allow our box to be self-aware. With the blueprint, new
can now builds our box exactly to our specifications.............
Click here for Download PDF / FREE
0 commentaires: