10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 2-8. IPrintjob.as<br />

package printcenters<br />

{<br />

public interface IPrintjob<br />

{<br />

function start(fn:String):void;<br />

}<br />

}<br />

Example 2-9 and Example 2-10 show the two concrete print job classes that implement<br />

the IPrintjob interface.<br />

Example 2-9. InkjetPrintjob.as<br />

package printcenters<br />

{<br />

internal class InkjetPrintjob implements IPrintjob<br />

{<br />

public function start(fn:String):void<br />

{<br />

trace("Printing '" + fn + "' to inkjet printer");<br />

}<br />

}<br />

}<br />

Example 2-10. WorkgroupPrintjob.as<br />

package printcenters<br />

{<br />

internal class WorkgroupPrintjob implements IPrintjob<br />

{<br />

public function start(fn:String):void<br />

{<br />

trace("Printing '" + fn + "' to workgroup printer");<br />

}<br />

}<br />

}<br />

Creator Classes: Print Centers<br />

Example 2-11 shows the class PrintCenter that should behave as an abstract class.<br />

The factory method is called createPrintjob( ), and client access to the printer centers<br />

is through the print( ) method.<br />

Example 2-11. PrintCenter.as<br />

package printcenters<br />

{<br />

import flash.errors.IllegalOperationError;<br />

// ABSTRACT Class (should be subclassed and not instantiated)<br />

public class PrintCenter<br />

76 | Chapter 2: Factory Method Pattern

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!