![]() |
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? |
I started by making a class for images(resizing, adding watermarks, making thumbnails).
|
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:
|
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