Minimalist Abstract Singleton | 107
Save the file asBadImplementation.asin the same folder as theSingleton.as.Ina
Flash document, type inBadImplementationin the Document class window, and test
the application. As predicted, you get a compiler error as shown in Figure 3-2.
Immediately you see that the Singleton constructor contains an argument, a
PrivateClass, and so the natural response is to change the code to include a
PrivateClass argument as shown in Example 3-6.
Re-save theBadImplementation.asfile and test it again. This time, you get a different
error as shown in Figure 3-3:
{
public function BadImplementation( )
{
var mySingleton=new Singleton( );
}
}
}
Figure 3-2. Compiler error expecting argument
Example 3-6. Attempt to add private class parameter
package
{
import flash.display.Sprite
public class BadImplementation extends Sprite
{
public function BadImplementation( )
{
var mySingleton=new Singleton(new PrivateClass( ));
}
}
}
Example 3-5. BadImplementation.as (continued)