Ninjakreborn Posted January 25, 2010 Share Posted January 25, 2010 I have been using functions for a long time. Long ago I got obsessed with Classes and started using them for everything..but lately I am starting to wonder if that is the best idea. A function is re-usable code that is brought together in an organized purpose for re-use at future times. A class is a collection of related values, properties, methods that allow for a specific task to become easier. In this situation a class generally has something that is done..but the system remembers what was done. For example you use variables to contain data that passes back and forth through various functions..that's why your able to advanced operations on just a few lines of code. Functions are not the same way..they are each separate parts of re-usable code that aren't connected (necessarily). So what I usually have been doing is creating a class..but their not always related to the same things. I have actually been making classes with a collection of random functions. It's not like file handling..creating a class that can deal with file handling..you can call a few parameters to setup what files and then start calling the class functions to automatically handle everything. So in this situation I am starting to wonder if a random collection of unrelated functions brought together into a class is a waste of time.. Since I am also losing the benefits that a class helps to bring. What are your thoughts on this and how you decide what your going to make into functions and what your going to make into classes. By the way I debated on where this should go...if I put it into the wrong area feel free to move it. Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 25, 2010 Share Posted January 25, 2010 So in this situation I am starting to wonder if a random collection of unrelated functions brought together into a class is a waste of time.. Not a waste of time maybe, but certainly not the best possible usage of classes/OOP. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted January 25, 2010 Author Share Posted January 25, 2010 That's what I was thinking..so my thoughts are starting to be, to take my functions and split them up into which functions are related..creating me a php page that has different classes within the pages for different related functions so I can use the Classes/oop power better. Then below my classes perhaps have all of my unrelated functions that are randomly used. Since I have 4-5 file handling functions I can put them together into one class, then group them separately. Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 25, 2010 Share Posted January 25, 2010 What you're doing is basically emulating namespaces with classes. While it is not necessarily a bad practice, you should realise you don't use a potential of OOP this way. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.