From Procedural to OO. What to turn into classes?
Posted: Sat Mar 07, 2009 3:06 pm
I have a very simple website that lets users submit custom cd labels and in turn lets others download the labels. I am just getting started in the OO world of programming and am having trouble getting into the right mind set. I understand the theory (I think) but am having trouble converting the procedural code I have into OO. For example, I have a class called "labels" that defines the attributes of a label and has the methods that allow for getting and setting those attributes. I also have a database class for interacting with my Mysql database that stores the labels. What I am failing to understand is how to glue these classes together. When someone goes to my site (shameless plug http://www.customcdlabels.com) and the index.php page is called, it calls a page called newlabels.php that queries the database for labels submitted within the last 10 days and creates a list of links to these labels. Is index.php supposed to be some sort of master controller class/object or is it supposed to remain a normal php script? Would my newlabels.php script be considered an object or would it simply be a method in the labels class that queries the database and returns the newest labels? It is relatively easy to identify an object when you can assign attributes to it but I am getting confused with how abstract I should go with objects and when I should decide that I just have a method and not an object but no particullarly good place to put this method. Any pointers are greatly appreciated.
Marc
Marc