ActionScript 3.0 Design Patterns

(Chris Devlin) #1

420 | Chapter 11: Strategy Pattern


As you can see, you can do quite a bit with a single method. To add more options to


sorting, add some implementations using theArray.sortOn( )method and multi-


dimension arrays.


Support Classes


Two support classes help keep the main test application clear, and make good use of


the whole idea of a class structural arrangement. TheShowTextclass (Example 11-31)


organizes a dynamic text field, andTextShow (Example 11-32) provides the format.


Example 11-29. SortAll.as


package
{
//Concrete Strategy
class SortAll implements SortWork
{
public function sorter(a:Array):Array
{
a.sort(Array.CASEINSENSITIVE);
return a;


}

}

}

Example 11-30. SortBack.as


package
{
//Concrete Strategy
class SortBack implements SortWork
{
public function sorter(a:Array):Array
{
a.sort(Array.CASEINSENSITIVE | Array.DESCENDING);
return a;


}
}
}


Example 11-31. ShowText.as


package
{
import flash.text.TextField;
import flash.text.TextFieldType;


class ShowText extends TextField
{
public function ShowText( ):void

Free download pdf