Date: 07/06/07 (PHP Community) Keywords: php, database, java Hey all, I'd like to consider myself pretty decent at PHP, but I've only recently started to move my projects into the realm of the object-oriented. Until now I've only used OO with Java and a bit of C++. Essentially I'm trying to encapsulate a database using objects. The issues are primarily with managing the complexity of the data model. I have a database table for users, let's call it users, and this table has fields along the lines of userid and displayname. I've created a User class which instantiates to a User object. Each of the fields (a/k/a columns) from the database is a so-called Field object. (So now a User object is a collection of Field objects). Internally, there is just an array of Field objects. To be able to display these Fields in different ways in the output, I've abstracted the display of the Field object into a FieldPrototype Object, which also contains information about the Field's data type (e.g. integer). So User is a collection of Fields, which is a FieldPrototype and a value which is accessed and according to the FieldPrototype. I anticipate that there may be up to several hundred of these objects instantiated at a time (and efficiency is a concern), so I've made the FieldPrototypes static members of the User class. Thus, if there are 100 User objects instantiated, each of them only carries around a value and an address of a FieldPrototype that is used to display and describe the Field. My question, then is how logically this is laid out and if the added burdens of creating static objects as descriptors of instantiated objects is worth the performance increase (or really if there even is a performance increase). I've put some time into this code already, visible at this page (user: lj, pass: lj). If it helps... Most of what I'm talking about takes place in the User.php file. This promises to be a fairly large project, and I'd like some experienced input before I go off and implement a system on fundmantally-flawed ideas. Also, anyone have any good resources (or book suggestions) for this sort of stuff with PHP? That is, Object Oriented + Database on a relatively large scale? Thanks in advance! You all are great.
|