Brent Clements wrote:
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
Brent,
there are many ways so skin a cat, but one way to solve your problem in an OO manner would be a container class, call it projects or what you will.
An example(not tested) could be:
<?php
class Container {
private projects = array(); // Contains projects
private projectsLoaded = false;
...
other methods
...
public function getProjects() {
if (!$this->projectsLoaded) {
$this->loadProjects();
}
return $this->projects;
}
private function loadProjects() {
//code to load the projects into the project array
$this->projectsLoaded = true;
}
}
?>
In your main code you can have something like:
$container = new Container;
foreach($container->getProjects as $project) {
$something = $project->someMethod(...);
...
...
}


Hope this helps. . .  Dusty

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to