Here's another way of thinking about the problem - is there actually any different between a MathQuestion and a WordQuestion? To me, it sounds like they are both Question objects and you could differentiate between the different types via composition.
You could start by defining an Enum class which lists the different types of Questions which appear in your Quiz (strictly speaking ActionScript 3 does not have proper Enums, but we can still achieve type safety with the following code.)
public class QuestionType {
public static const MATH : QuestionType = new QuestionType("math");
public static const WORLD : QuestionType = new QuestionType("world");
private var _name : String;
// Private constructor, do no instantiate new instances.
public function QuestionType(name : String) {
_name = name;
}
public function toString() : String {
return _name;
}
}
You can then pass one of the QuestionType constants to the Question Class when you construct it:
public class Question {
private var _message : String /* Which country is Paris the capital of? */
private var _answers : Vector.<Answer>; /* List of possible Answer objects */
private var _correctAnswer : Answer; /* The expected Answer */
private var _type : QuestionType; /* What type of question is this? */
public function Question(message : String,
answers : Vector.<Answer>,
correctAnswer : Answer,
type : QuestionType) {
_message = message;
_answers = answers.concat(); // defensive copy to avoid modification.
_correctAnswer = correctAnswer;
_type = type;
}
public function getType() : QuestionType {
return _type;
}
}
Finally, a client (the code which makes use of the Question object) can query the question type easily:
public class QuizView extends Sprite {
public function displayQuestion(question : Question) : void {
// Change the background to reflect the QuestionType.
switch(question.type) {
case QuestionType.WORLD:
_backgroundClip.gotoAndStop("world_background");
break;
case QuestionType.MATH:
_backgroundClip.gotoAndStop("math_background");
break;
}
}
}