我有一个从超类调用方法的子类.超类中的方法使用在超类中定义为抽象(不是真正抽象)但在子类中实现的方法.
例如:
package BaseClass;
sub new
{
}
sub method1 {
return someAbstractMethod();
}
sub someAbtsractMethod
{
die "oops, this is an abstract method that should " .
"be implemented in a subclass" ;
}
1;
package SubClass;
sub new
{
}
sub someAbtsractMethod
{
print "now we implement the asbtract method";
}
1;
Run Code Online (Sandbox Code Playgroud)
现在我做的时候:
$sub = new SubClass();
$sub->method1();
Run Code Online (Sandbox Code Playgroud)
...它调用抽象消息,我得到指定的错误消息.如果我从超类中取出抽象方法并将实现留在子类中,它就不会识别该方法并且我得到子程序抽象方法未找到错误.