« Patrons de conception/Objet composite » : différence entre les versions

Contenu supprimé Contenu ajouté
imported>Konandrum
imported>Drewprod
Ligne 148 :
class Component
{
 
// Attributes
private $basePath;
private $name;
Ligne 154 ⟶ 156 :
public function __construct($name, CDirectory $parent = null)
{
// Debug : echo "constconstructor Component";
$this->name = $name;
$this->parent = $parent;
Ligne 167 ⟶ 169 :
}
}
 
 
// Getters
public function getBasePath() { return $this->basePath; }
public function getName() { return $this->name; }
public function getParent() { return $this->parent; }
// Setters
public function setBasePath($basePath) { $this->basePath = $basePath; }
public function setName($name) { $this->name = $name; }
public function setParent(CDirectory $parent) { $this->parent = $parent; }
// Method
public function getPath() { return $this->getBasePath().'/'.$this->getName(); }
}
Ligne 181 ⟶ 187 :
class CFile extends Component
{
// Attributes
private $type;
 
public function __construct($name, $type, CDirectory $parent = null)
{
// Debug : echo "constructor CFile";
$this->type = $type;
 
// Retrieve constructor of Component
parent::__construct($name, $parent);
}
// Getters
public function getType() { return $this->type; }
 
// Setters
public function setType($type) { $this->type = $type; }
 
// Methods of Component class
public function getName() { return parent::getName().'.'.$this->getType();
public function getPath() { return parent::getPath().'.'.$this->getType(); }
Ligne 198 ⟶ 214 :
class CDirectory extends Component
{
 
// Attributes
private $childs;
public function __construct($name, CDirectory $parent = null)
{
// Debug : echo "constconstructor CDirectory";
$this->childs = array();
 
//echo "const CDirectory";
// Retrieve constructor of Component
parent::__construct($name, $parent);
}
 
// Getters
public function getChilds() { return $this->childs; }
 
// Setters
public function setChilds($childs) { $this->childs = $childs; }
 
 
// Methods
public function addChild(Component $child)
{
Ligne 234 ⟶ 259 :
?>
</source>
Exemple d'utilisation (''example of use''):
<source lang=php>
<?php
Ligne 248 ⟶ 273 :
?>
</source>
résultat à l'écran (''result on the screen'') :
 
root