Template Method(模板方法)模式AS2实现
类别: Flash教程
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();
}
}
{
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();
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();
- 上一篇: FSCommand 用法详解
- 下一篇: AS的基本代码解释
-= 资 源 教 程 =-
文 章 搜 索