O'Reilly logo

ActionScript 3.0 Design Patterns by Chandima Cumaranatunge, William Sanders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extended Example: Color Printing

The print shop has been going gangbusters! The manager decided to add the single most requested feature at the shop – color printing. We end up purchasing two new color printers: a color inkjet printer for low volume jobs, and a color laser printer for high volume printing. Unfortunately, we didn't think about color printing when first designing the application. How do we add this feature to our application? It's a good thing that we know about parameterized factory methods.

We still have the two print centers for high and low volume printing. However, we now have to specify a kind of print job. Customers can request a color or black and white print job that can be high or low volume. To indicate the kind of print job, we can pass a parameter to the print() method.

New Product Classes

We add two new product classes for the new printers, called ColorInkjetPrintjob (Example 2-16) and ColorLaserPrintjob (Example 2-17). Again, we're not changing existing code, but extending the application by implementing to the IPrintjob interface show in Example 2-8.

Example 2-16. ColorInkjetPrintjob.as

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

Example 2-17. ColorLaserPrintjob.as

package printcenters { internal class ColorLaserPrintjob implements IPrintjob { public function start(fn:String):void { trace("Printing '" + fn + "' to color ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required