I currently am developing a webapp and I haven't used OOP techniques at all and I'm starting to get overwhelmed with unmanageable code. I've decided to convert this project into an OOP design. My problem is that I've never done OOP before so I don't quite understand the logic about when or what to make objects. I know what OOP is and how to make classes, I just don't know what objects to make.
For example, look at my current webapp:
Would you make one class called "Record" and make methods to do actions on the source, processing, bagging, grading and finished product stuff or do each of those go in their own class and objects with methods to do actions on each. I just don't understand where or what to make my objects.
This will be my first time doing OOP. Hopefully someone can clear this up for me.
The most common way to do is is to create a PHP class per database table. Each of these classes then has the fields of the database as class fields. You can either choose to make them protected in the class and then use getters/setters to manipulate them, or just go with public fields and manipulate the values directly. The advantage of getters/setters is that you can do some gate keeping, i.e., raising errors like "The value of x must not exceed y" and stuff like that.
Beside those classes you also need a mechanism to store/retrieve those objects from the database. The way I see this there are two ways you can do this.
First, you can have all your classes extend a superclass and create all methods for storing/retrieving data in that superclass, or (second) you can create a separate class (or a bunch of classes that work together) whose responsibility it is to store/retrieve all data.
Ouch, my current app has between 30 and 40 tables at any given time during development. Right now I'm at 33 again.
This topic is now closed. New replies are no longer allowed.