Here's a little recursion problem I'd like some input on - the task, to
remove recursion from this little set of 3 classes, without removing any
functionality.
more classes and interfaces can be added - if I get a solution I'll mail
it in.
additional question.. quite sure this isn't actually called recursion as
it's more than one class involved.. so what is it called?
<?php
class Town {
private $id;
private $townInformationCollection;
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getTownInformationCollection() {
return $this->townInformationCollection;
}
public function setTownInformationCollection(
TownInformationCollection $townInformationCollection)
{
$this->townInformationCollection = $townInformationCollection;
}
}
class TownInformationCollection {
private $townInformationArray = array();
public function getTownInformationArray() {
return $this->townInformationArray;
}
public function setTownInformationArray(array $townInformationArray) {
$this->townInformationArray = $townInformationArray;
}
public function addTownInformation(TownInformation $townInformation) {
$this->townInformationArray[] = $townInformation;
}
}
class TownInformation {
private $id;
private $information;
private $town;
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getInformation() {
return $this->information;
}
public function setInformation($information) {
return $this->information = $information;
}
public function getTown() {
return $this->id;
}
public function setTown(Town $town) {
$this->town = $town;
}
}
$town = new Town();
$town->setId(1);
$townInformation = new TownInformation();
$townInformation->setId(12);
$townInformation->setInformation('some random info');
$townInformation->setTown($town);
$townInformationCollection = new TownInformationCollection();
$townInformationCollection->setTownInformationArray(
array($townInformation) );
$town->setTownInformationCollection($townInformationCollection);
print_r( $town );
print_r( $townInformation );
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php