Almost Recursion
| From: | Nathan Rixham | Date: | Fri, 16 Jan 2009 19:29:54 +0000 |
| Subject: | Almost Recursion | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-286518@lists.php.net to get a copy of this message | ||
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 ); ?>