The Millenium Falcon has a crew of Han Solo, Chewbacca and Luke Sky Walker. Write the classes (included the Visitor class referenced below) you need to make the crew say (trace) their catchphrases (e.g. Chewy says "Gwaaraghhghll").
Class MilleniumFalcon
{
protected var han:Pilot
protected var chewbacca:Wookie;
protected var luke:Gunner;
function accept(visitor:IMilleniumFalconVisitor) : Void
{
visitor.visit(this)
}
function getCrew() : Array
{
return [han, chewbacca, luke]
}
}
Agree with adding the
addCrew
function although I would separate out the return boolean to another method - I've never liked the returning of booleans if it is not explicit what it is actually for - it also violates the SRP as technically that method does both "adding crew members" and "does crew member exist".You are almost there with the answer but there is a mistake with regards the type you are passing into the visitor - you have put type
Crew
whereas you pass in an object of typeMilleniumFalcon
.