ActionScript 3.0 Design Patterns

(Chris Devlin) #1

76 | Chapter 2: Factory Method Pattern


Example 2-9 and Example 2-10 show the two concrete print job classes that imple-


ment theIPrintjob interface.


Creator Classes: Print Centers


Example 2-11 shows the classPrintCenterthat should behave as an abstract class.


The factory method is calledcreatePrintjob( ), and client access to the printer cen-


ters is through theprint( ) method.


Example 2-8. IPrintjob.as


package printcenters
{
public interface IPrintjob
{
function start(fn:String):void;
}
}


Example 2-9. InkjetPrintjob.as


package printcenters
{
internal class InkjetPrintjob implements IPrintjob
{
public function start(fn:String):void
{
trace("Printing '" + fn + "' to inkjet printer");
}
}
}


Example 2-10. WorkgroupPrintjob.as


package printcenters
{
internal class WorkgroupPrintjob implements IPrintjob
{
public function start(fn:String):void
{
trace("Printing '" + fn + "' to workgroup printer");
}
}
}


Example 2-11. PrintCenter.as


package printcenters
{
import flash.errors.IllegalOperationError;


// ABSTRACT Class (should be subclassed and not instantiated)
public class PrintCenter

Free download pdf