Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
<?php
class people
{
private $people
function doSomething()
{
foreach ($this->$people AS $person)
{
//
}
}
function addPerson($person)
{
$this->people[] = $person;
}
}
class person
{
private $name;
private $age;
private $etc;
function setName($name){}
function setAge($age){}
function setEtc($etc){}
}
$people = new people();
$bob = new person();
$bob->setName('bob');
$bob->setAge(33);
$bob->setEtc('etc');
$people->addPerson($bob);
Should person class extends people class and perhaps have a method called add()? which adds it to the people property? Or should it be two separate classes like I have it above?
EDIT| This is pseudo-code.. it's just the concept I'm after.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
That is a good question, lol.
It does not extend or override - but it provides information to
Maybe I don't need an additional class?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Notice what Jenk mentioned - composition. If your People class is a collection of Person classes, then its probably best to use composition instead of inheritance. Of course, when dealing with pseudo code it's rather meaningless - those decisions need to be based on the relationships in the actual application.
The "people" object uses the collection of "person" objects to manipulate data supplied to the "people" class.
I'll just do what I think is best and post it in the critique forum.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.