TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-24-2008, 09:03 AM   #1 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default Getting started with OOP

I've read a ton of theory articles on OOP but I'm not sure where to go now.

Has anybody got a link to a tutorial that shows you how to make a class thats actually useful rather than 'person' or 'dog'?

What sort of stuff is good for beginners to try?
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
Old 09-25-2008, 07:08 AM   #2 (permalink)
The Wanderer
Good Samaritan 
 
martins256's Avatar
 
Join Date: Mar 2008
Posts: 18
Thanks: 0
martins256 is on a distinguished road
Default

I started by making a class for images(resizing, adding watermarks, making thumbnails).
martins256 is offline  
Reply With Quote
Old 09-25-2008, 02:50 PM   #3 (permalink)
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
Old 09-26-2008, 02:12 AM   #4 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

Another idea for a class is to validate input. I have one that validates phone numbers, emails ect so that I can update it sitewide quickly.
CoryMathews is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:19 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design