Well, if I get you right, you have a class named Project holds information about a project. Now you want a list of the current projects. I'd make a new class, named ProjectList or something similar, that can be used to administrate your projects.I've always wondered this about OOP and maybe you guys can answer this question.
I'm writing a php application and I'm trying to figure out the correct way to right the oop part of this application.
for instance.
I have a "project.class" file that has functions for dealing with individual projects because you break down ideas into singular entities in OOP(as I understand it)
But what if I wanted to deal with multiple projects such as getting a list of the projects in my database, should I create a function in the "project.class" to handle the now plural request, or should I create a "projects.class" file that has a function called "getProjects".
Hopefully I'm explaining this question right. It makes sense in my own head. :-)
Thanks, Brent
class Project { public $name; // The project's name public $ownerID; // The user ID of the project's owner /* The constructor. Note: this only works in PHP5 */ public function __construct ($id) { $db = mysql_connect(); // Get project info... $this->name = $result['name']; $this->ownerID = $result['owner']; } }
class ProjectList { public $projects = array();
public function __construct () { $db = mysql_connect(); $query = mysql_query('SELECT id FROM projects'); $result = mysql_fetch_array($query);
foreach ($result as $project_id) { $this->projects[$project_id] = new Project($project_id); } }
public function listProjects () { return $this->projects; }
public function addProject ($name, $owner) { // ... }
public function deleteProject ($id) { // ... } } -- Daniel Schierbeck
Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/register&r=6584
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php