Class Product
{
Private var classname: String;
Private function product (), PRODUCT ()
{
}
Public function get classname (): string
{
Return ClassName;
}
}
Class Creator
{
// conncture
Private function creator ()
{
}
//Methods
Public Function FactoryMethod (): Product
{
Return;
}
}
Class ConcreteProducta Extends Product
{
Public Function ConcreteProducta ()
{
ClassName = "concreteproducta";
}
}
Class ConcreteProductB Extends Product
{
Public Function ConcreteProductB ()
{
ClassName = "ConcreteProductb";
}
}
Class Concretecreatora Extends Creator
{
//Methods
Public Function FactoryMethod (): Product
{
Return New ConcreteProducta ();
}
}
Class Concretecreatorb EXTENDS CREATOR
{
//Methods
Public Function FactoryMethod (): Product
{
Return New ConcreteProductB ();
}
}
//client.fla
// FactoryMethod Returns Producta
Var c: creator = new concretecreatora ();
VAR P: product = C.FactoryMethod ();
Trace ("Created P.className);
// FactoryMethod Returns ProductB
C = new concretecreatorb ();
P = C.FactoryMethod ();
Trace ("Created P.className);
// Output
// Created ConcreteProducta
// Created ConcreteProductB