TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Getting started with OOP (http://www.talkphp.com/advanced-php-programming/3375-getting-started-oop.html)

Jmz 09-24-2008 09:03 AM

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?

martins256 09-25-2008 07:08 AM

I started by making a class for images(resizing, adding watermarks, making thumbnails).

Village Idiot 09-25-2008 02:50 PM

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.

CoryMathews 09-26-2008 02:12 AM

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.


All times are GMT. The time now is 11:34 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0