OOP and Classes. can you help me understand the theory?
Posted: Thu Oct 27, 2011 5:55 pm
Hey everyone, I'm new on here (i have introduced myself here: viewtopic.php?f=6&t=9704&start=870 )
My question is about why we use classes and OOP rather than functions. I am not yet doing this although i have tried, but i keep finding myself using classes in exactly the same way as I would use a function.... only it takes more code. Now, I know that's not how they are supposed to be used but my head just seems to work that way.
For example, I will have some functions that I like to use often in a separate php file, then when I want to use them, I include the file at the top of my script and run the functions when I need them.
I understand that you can use classes the same way but I'm sure there is more to them than that. Sometimes i even call functions by a variable $myFunctionName($myParams) but I dont know any more efficient way of coding. I'm sure classes are more efficient, but I cant get my head around WHEN they are more efficient.
Can we please discuss how and when I should use classes and how they can be more effective?
My question is about why we use classes and OOP rather than functions. I am not yet doing this although i have tried, but i keep finding myself using classes in exactly the same way as I would use a function.... only it takes more code. Now, I know that's not how they are supposed to be used but my head just seems to work that way.
For example, I will have some functions that I like to use often in a separate php file, then when I want to use them, I include the file at the top of my script and run the functions when I need them.
I understand that you can use classes the same way but I'm sure there is more to them than that. Sometimes i even call functions by a variable $myFunctionName($myParams) but I dont know any more efficient way of coding. I'm sure classes are more efficient, but I cant get my head around WHEN they are more efficient.
Can we please discuss how and when I should use classes and how they can be more effective?