70 | Chapter 2: Factory Method Pattern
Theexamplepackage contains theProduct1andProduct2classes that implement the
IProductinterface. It also contains theabstractclassCreatorthat is extended by two
subclassesCreatorAandCreatorB. Each class is defined in its own file, as is the con-
vention with ActionScript 3.0. First, let’s take a look at the product classes.
Product Classes
Example 2-1 through Example 2-3 show the product interface and concrete product
classes. All three classes belong to theexamplepackage as indicated by thepackage
declaration. TheIProductinterface declares a method calledmanipulate( )that is
implemented by both product classes. True to a minimalist example, the product
classes don’t do much of anything. However, make note of the class attribute.
Example 2-1. IProduct.as
package example
{
public interface IProduct
{
function manipulate( ):void;
}
}
Example 2-2. Product1.as
package example
{
internal class Product1 implements IProduct
{
public function manipulate( ):void
{
trace("Doing stuff with Product1");
}
}
}
Example 2-3. Product2.as
package example
{
internal class Product2 implements IProduct
{
public function manipulate( ):void
{
trace("Doing stuff with Product2");
}
}
}