Chad,
OOP is a concept that is applicable to several languages like C++, PHP, Java, JavaScript...
OOP centers on having an <b>object</b> or a
<b>class</b>.
Class or Object on the other hand is consisting of two parts.
- Properties - describe what object <b>IS</b>.
- Methods or functions - describe what object can <b>DO</b>
--------------------------------------------
Let's take a real life example like a <b>car</b>.
Class Car
{
1. Properties of a car
<ul>
<li>paint color (black, yellow, blue...)
<li>engine size (1.5 liter, 8 liter...)
<li>engine type (4 cylinder, V-8...)
<li>style (coupe, sedan...)
<li>transmission (automatic, manual)
etc...
</ul>
2. Methods or functions of the car
<ul>
<li>Stopping
<li>Driving
<li>Using blinkers
<li>Using windshield wipers
<li>Reverse dirving
etc...
</ul>
}
So as you can see almost anything can be broken down into categories of properties and methods. (Human body, computer, telephone, pencil sharpener, watch, nail cutter, scizzors... you name it).
Same approach is applied toward programming.
Class Calculator
{
<b>//Defining class properties</b>
var $num1;
var $num2;
var $res;
<b>//Defining class methods</b>
function add($n1, $n2)
{
$this->num1=$n1;
$this->num2=$n2;
$this->res=$this->num1+$this->num2;
echo "Sum is $this->res";
}
function subtract($n1, $n2)
{
$this->num1=$n1;
$this->num2=$n2;
$this->res=$this->num1+$this->num2;
echo "Subtraction is $this->res";
}
}
So let's say that you save this class as calculator.inc.
Then you have a form
<form method=post action=Calculate.php>
<select name=op>
<option value=add>Add</option>
<option value=sub>Subtract</option>
</select>
<input type=text name=nm1>
<input type=text name=nm2>
<input type=submit value=Calculate>
</form>
Then here comes your processing script
include("calculator.inc"); //include your class
$obj=new Calculator; //instantiate your calculator class
if($op=="add")
{
$obj->add($nm1, $nm2);
}
if($op=="sub")
{
$obj->subtract($nm1, $nm2);
}
That's it... great thing about OOP is that if you need to make updates you modify your calculator class - that's the only file you have to tinker with - all other components are set.
Hope that gives you some ideas,
Di