184 | Chapter 5: Adapter Pattern
The client would generate the following output. These aretracestatements that
indicate which class and method produced the output.
Called Adaptee:requestA( )
Called Adapter:requestB( )
Called Adaptee:requestC( )
Called Adapter:requestD( )
The method declarationrenamedRequestA( )is simply a name change to a method
whose implementation is already available in theAdaptee. This conversion is imple-
mented by directing the request torequestA( ) in theAdaptee.
MethodrequestB( )is available inAdaptee,but theAdapterhas overridden and re-
implemented it because the existing functionality wasn’t what was needed.
MethodrequestC( )is available inAdapteeand the method call passes directly to it.
This is the primary advantage of using inheritance: you don’t have to implement a
method if you need the functionality andmethod signatureimplemented in the
Adaptee.
MethodrequestD( )is implemented in theAdapter. TheAdaptorclass isn’t required
to use theAdapteeclass to implement everything. The adapter can have custom
{
trace("Called Adapter:requestD( )");
}
}
}
Example 5-8. Main.as
package
{
import flash.display.MovieClip;
/**
- Main Class
- @ purpose: Document class for movie
*/
public class Main extends MovieClip
{
public function Main( )
{
var target:ITarget = new Adapter( );
target.renamedRequestA( );
target.requestB( );
target.requestC( );
target.requestD( );
}
}
}
Example 5-7. Adapter.as (continued)