topical media & game development
professional-php-02-sampleCode.php / php
<?php
interface Band {
public function getName();
public function getGenre();
public function addMusician();
public function getMusicians();
}
interface Musician {
public function addInstrument();
public function getInstruments();
public function assignToBand();
public function getMusicianType();
}
interface Instrument {
public function getName();
public function getCategory();
}
class Guitarist implements Musician {
private first;
private instruments;
private first, this->last = this->first = this->instruments = array();
this->first . " " . instrument) {
array_push(instrument);
}
public function getInstruments() {
return this->band) {
bandReference = this->musicianType;
}
public function setMusicianType(this->musicianType = last, last, this->setMusicianType("lead guitarist");
}
}
class RockBand implements Band {
private bandGenre;
private bandName) {
bandName;
this->bandGenre = "rock";
}
public function getName() {
return this->bandGenre;
}
public function addMusician(Musician this->musicians, musician->assignToBand(this->musicians;
}
}
class Guitar implements Instrument {
private category;
function __construct(this->name = this->category = "guitar";
}
public function getName() {
return this->category;
}
}
// Test Objects
bandMemberA = new Guitarist("Jack", "Float");
bandMemberA->addInstrument(new Guitar("Gibson Les Paul"));
bandMemberB->addInstrument(new Guitar("Hondo H-77"));
bandMemberA);
bandMemberB);
foreach(musician) {
echo "Musician ".musician->getMusicianType() . "<br>";
echo "in the " . musician->getBand()->getName() . "<br>";
foreach(instrument) {
echo "And plays the " . instrument->getCategory() . "<br>";
}
echo "<p>";
}
?>
(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.