Jump to content

Why use classes?


spyke01

Recommended Posts

Ok there will probally be much flaming about this, but here goes. ive seen many people using classes, but ive never used them simply because i dont see a reason to do it in my code. I have seen where people use it to access different style databses, kinda like phpbb does. ive programmed forums, content management systems, trouble ticket systems, and store systems but never once used a class. So heres my question, when(please use a real world example) would i really need to use them? how much more effecient is if to use a class instead of functions with global variables?
Link to comment
Share on other sites

The larger the project, the more global variables and functions collide. What if you wanted to use a friends code that had a bunch of global variables that overwrote yours? I haven't done a lot of OPP, and the little I have done has been in Perl, not PHP. Before I understood what it was, I had the same notion as you--What's the point? This is understood in time. Any basic OPP primer should lay out the advantages for you, such as abstraction and inheritance. I see it as a containment system. You have your own "namespace" in which you cannot run into anyone else, and you can also control what the user can and cannot do within this area--private or public methods, e.g.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.