OOP .. I just don't get it.
| From: | mojo jojo | Date: | Tue, 05 Mar 2002 20:22:20 +0000 |
| Subject: | OOP .. I just don't get it. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-87337@lists.php.net to get a copy of this message | ||
Hi
I've been using php for a while now but I have not got my head around OOP
(classes).
Why bother using them? I've read thru a few tutorials on using classes and
the examples given are quite simple. This is probably the problem - I just
can't see the benefit of using this style of programming.
Here is what I'm getting at.
------------USING A CLASS-----------------
class Table {
var $rows;
var $columns;
function MakeTable() {
draw a table with $this->columns as the number of columns
and $this->rows as the number of rows
}
}
$mytable = new Table;
$mytable->rows = 5;
$mytable->columns = 10;
$mytable->MakeTable();
---------------USING A NORMAL FUNCTION-----
function MakeTable($rows,$columns) {
make a table with $rows as the number of rows
and $columns as the number of columns
}
$rows = 5;
$columns = 10;
MakeTable($rows,$columns);
-----------------------------------------------------------
Using a class doesn't appear to give me any benefits - in fact the code is
longer.
I know that you can spawn more instances of the same class which sounds
useful, however I can also run my function as many times as I like using
different variables.
What am I missing here?
Thanks
Mojo