topical media & game development
professional-php-04-CompositePatternDemo.php / php
<html>
<body>
<head>
<style>
body {font : 12px verdana; font-weight:bold}
td {font : 11px verdana;}
</style>
</head>
<?php
abstract class AbstractInstrument {
private category;
private instrument) {
array_push(instrument);
}
public function remove(AbstractInstrument & this->instruments);
}
public function hasChildren() {
return (bool)(count(i) {
return this->getName();
if (this->instruments as instrument->getDescription();
echo "</td></tr></table>";
}
}
}
public function setName(this->name = this->name;
}
public function setCategory(this->category = this->category;
}
}
class Guitar extends AbstractInstrument {
function __construct(name);
parent::setCategory("guitars");
}
}
class DrumSet extends AbstractInstrument {
function __construct(name);
parent::setCategory("drums");
}
}
class SnareDrum extends AbstractInstrument {
function __construct(name);
parent::setCategory("snare drums");
}
}
class BaseDrum extends AbstractInstrument {
function __construct(name);
parent::setCategory("base drums");
}
}
class Cymbal extends AbstractInstrument {
function __construct(name);
parent::setCategory("cymbals");
}
}
drums->add(new SnareDrum("snare drum"));
cymbals = new Cymbal("zildjian cymbal set");
cymbals->add(new Cymbal("large high hat"));
cymbals);
drums->getDescription();
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.