objects that interact with each other
Posted: Tue Oct 26, 2010 5:48 am
Consider the following example:
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.
Code: Select all
<?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);EDIT| This is pseudo-code.. it's just the concept I'm after.