View Single Post
Old 01-18-2008, 10:10 PM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Hi Sarmenhb,

The main benifit (and aim) of using classes is that they are self-contained reusable blocks of code. For example, if I wrote a class to generate PDF files, you could then take that class, drop it into your www folder, and do something like:

PHP Code:
<?php

include_once('class_pdf.php');
$pdf = new Pdf();
$pdf->contents('some text here to put in your new PDF file');
$pdf->save('myfile.pdf');
No need to mess about copy/pasting code from my files to yours, or trying to fit the entire PDF generator into a single function.

Also, you could easily extend my PDF-generator class to include fuctions and features of your own without having to alter my original code. Your extended class could then be given to someone else who could use it without having to make a bunch of edits to my code to get it to work.

And finally, keeping your code in nicely organized self-contained classes makes them a lot easier to maintain on large projects

There are many other benifits but these are the most important ones to me.

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote