![]() |
OOP: Best place to load data in
Hi all,
I'm trying to recreate my blog using OOP and having a problem working out how to solve the following problem.. I have an ArticleCollection class (extends Collection class) that stores Articles (singleton's -is that right?). Currently Articles takes a single parameter (article_id) and loads the information from a database. I want ArticleCollection to loop through all the records in my database and create a new Article instance, then store it in an array / object, so I can access them when I want. This is where I'm getting troubled, I would need to connect to the DB in ArticleCollection (for all records) AND Article (for the individual record), this smell's like I'm duplicating code. How should I approach this? I've not written any code yet, trying to get it clear in my head before I set out. Cheers. |
Ok, I've solved it myself, I'll post back soon with a code implementation so that other's with the same question can see how I went about it.
|
I've had the same issue myself. I made a system which has a client model object and a clients object (the clients object contains all the client objects). The clients object gets a list of all the clients ID's then creates a new client model object for each ID.
I'd like to see your solution. |
| All times are GMT. The time now is 08:22 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0