Working with String Strategies | 417
stringWork( )andsortWork( ). These references are then used to specify exactly
which of the concrete strategies each will be using.
Keep in mind that both of these classes inherit the methods of the main context
class,StringChecker, and when you test instances of these classes, you will be using
theworkStrings( ) andworkSorts( ) methods.
String Strategies
The classes associated with the strategies are quite simple by comparison to the cli-
ent classes in the Strategy design pattern. The interfaces specify the methods, and
then each of the concrete strategy classes implements them, supplying the details in
the form of algorithms. However, in this example (Examples 11-24 and 11-25), both
methods in the interfaces require parameters and expect returns.
Example 11-22. Checker.as
package
{
//Concrete Context
class Checker extends StringChecker
{
public function Checker( )
{
stringWork = new EmailCheck( );
sortWork = new SimpleSort( );
}
}
}
Example 11-23. Passwork.as
package
{
//Concrete Context
class Passwork extends StringChecker
{
public function Passwork( )
{
stringWork = new PasswordVerify( );
sortWork = new SortAll( );
}
}
}