Template Method(模板方法)模式AS2实现
class AbstractClass
{
private function AbstractClass()
{
}
// Methods
public function PrimitiveOperation1():Void
{
}
public function PrimitiveOperation2():Void
{
}
// The Template method
public function TemplateMethod():Void
{
trace("In AbstractClass.TemplateMethod()");
PrimitiveOperation1();
PrimitiveOperation2();
}
}
// "ConcreteClass"
class ConcreteClass extends AbstractClass
{
// Methods
public function PrimitiveOperation1():Void
{
trace("Called ConcreteClass.PrimitiveOperation1()");
}
public function PrimitiveOperation2():Void
{
trace("Called ConcreteClass.PrimitiveOperation2()");
}
}
//Context.fla
var c:ConcreteClass = new ConcreteClass();
c.TemplateMethod();