ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Summary | 203

Summary


The adapter pattern allows existing classes to be used in situations that didn’t exist


or weren’t anticipated when they were developed. For example, an application can


have a lot of legacy code, code that is no longer supported or maintained, but needs


to be used for various reasons. Adaptor classes use or extend existing code to fit new


requirements. The main focus of the adapter pattern is to convert the interface of the


existing class to one that fits a new context.


Adapter patterns are very close in intent and in function to several other patterns


such as the façade, decorator (see Chapter 4), and bridge. The primary distinctions


are that the adapter requires a target interface to which the adapter provides the


implementation, there has to be an existing class that the adapter uses or extends to


provide the implementation, and there is no requirement to simplify the interface.


There are two types of adapters, and choosing between object and class adapters


highlights the advantages and disadvantages of composition versus inheritance in


implementation. They also illustrate the importance of interfaces, and how they


allow the designer to encapsulate implementation details.

Free download pdf