View Single Post
Old 09-25-2008, 02:50 PM   #3 (permalink)
Village Idiot
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Classes are not random containers. Classes are for things you will use over and over again and don't want to re-define many times. Even in large applications, I will generally only have a small number of classes. A good use of them is for a member system, you are going to do the following many times in the script:
-Login
-Authentication (you do that on every page)
-Registration
-Account deletion
-Account information checks

Now all you need is a database that that class and you have the back end for a user system. It makes things easier to use a class for that.

Classes are also useful for abstracting a given purpose from the system. Lets say you where going to do that image resizer. You would want to make it fully self contained, so the code will with with just the class. It could look something like this:
PHP Code:
include "imageResizer.php";
$image = new imageResizer;
$image->loadJPEG("path");
$image->resizeImage(150,150);
$image->showImage(); 
That way you can reuse that code with just the class file. This makes it easy to distribute to others and use in multiple things without integrating it to to script.
__________________

Village Idiot is offline  
Reply With Quote