[nycphp-talk] How many of you guys are "down" with Java/OO - likeprogramming concepts?
Jose Villegas
jv_nyphp at duikerbok.com
Wed Feb 18 22:46:36 EST 2004
I don't use classes in my code unless I see a real benefit.
One benefit of putting your functions in a class is that it simplifies
your namespace. For example, if you have a whole bunch of templating
functions, you can create a class named "Templates" for them. A
printing function would then be $templateObject->print() instead of
templatePrint(). You have to be more careful about names clashing with
the second approach as opposed to the first.
A second benefit is the ability to reuse variables instead of having to
pass them each time a function is called. Let's say you're going to do
a number of operations on a specific record in a database table. You
could create a class called DbRecord that takes the table name and a
name/value pair to identify the record:
$dbRecord = new DbRecord('color', 'blue', 'table_name');
You can then set up an update function to generate specific sql
statements and send database queries.
$dbRecord->update('material', 'suede');
This function would set up the SQL statement, 'UPDATE table_name SET
material="suede" WHERE color="blue"'.
Jose
More information about the talk
mailing list