Re: Silly OOP question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Brent Clements wrote:
or should I
create a "projects.class" file that has a function called
"getProjects".

Yes, that's a possibility. You can even create more stuff in this Projects class like createProject, removeProject and stuff like this. If these tasks are pretty static and you don't need multiple instances of the Projects class then you can implement it completely statically so you don't need to instanciate the class:


class Projects
{
    private static $projects = array();

    public static function getAll()
    {
        return self::$projects;
    }

    public static function add(Project $project)
    {
        self::$projects[] = $project;
    }
}

So now you can do this to get the projects:

  $projects = Projects::getAll();

Adding objects to the list can be done by the constructor of the Project class:

function __construct()
{
    Projects::add($this);
}

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux