Código PHP:
interface Band{
function getBandName();
function getGenre();
function addMusician(Musician $musician);
function getMusicians();
}
interface Musician{
function addInstrument(Instrument $instrument);
function getInstruments();
function assignToBand(Band $band);
function getMusicianType();
}
interface Instrument{
function getName();
function getCategory();
}
Código PHP:
class Guitarist implements Musician{
private $last;
private $first;
private $musicianType;
private $instruments;
private $bandReference;
function __construct($first, $last) {
$this->first = $first;
$this->last = $last;
$this->instruments = array();
$this->musicianType = "guitarist";
}
function getName(){
return $this->first . " " . $this->last;
}
function addInstrument(Instrument $instrument){
array_push($this->instruments, $instrument);
}
function getInstruments(){
return $this->instruments;
}
function getBand(){
return $this->bandReference;
}
function assignToBand(Band $band){
$this->bandReference = $band;
}
function getMusicianType(){
return $this->musicianType;
}
function setMusicianType($musicianType){
$this->musicianType = $musicianType;
}
}
Código PHP:
class BandaRock implements Banda{
.
.
.
function addMusician(Musician $musician){
array_push($this->musicians, $musician);
$musician->assignToBand($this);
}
Cita:
la pregunta es:
array_push($this->musicians, $musician);
aca agrega musician al array
$musician->assignToBand($this);
ACA LO QUE ENTIENDO ES QUE AGREGA EL MUSICO A ESTA BANDA O ES DECIR QUE AGREGA ESTE MUSICO A ESTA CLASE BAND
ES CORRECTO LO Q ENTIENDO
array_push($this->musicians, $musician);
aca agrega musician al array
$musician->assignToBand($this);
ACA LO QUE ENTIENDO ES QUE AGREGA EL MUSICO A ESTA BANDA O ES DECIR QUE AGREGA ESTE MUSICO A ESTA CLASE BAND
ES CORRECTO LO Q ENTIENDO