01-06-2012, 01:00 PM
Adapter
Adapter.ppt (Size: 319.5 KB / Downloads: 41)
What is Adapter?
Intent:
Change the interface of a class into another interface which is expected by the client.
Also Know As:
Wrapper
Applicability
Use an existing class whose interface does not match the requirement
Create a reusable class though the interfaces are not necessary compatible with callers
Want to use several existing subclasses, but it is impractical to subclass everyone. (Object Adapter Only)
Class Adapter Pattern
Pros
Only 1 new object, no additional indirection
Less code required than the object Adapter
Can override Adaptee's behaviour as required
Cons
Requires sub-classing (tough for single inheritance)
Less flexible than object Adapter
Conclusions
Allows collaboration between classes with incompatible interfaces
Implemented in either class-based (inheritance) or object-based (composition & delegation) manner
Useful pattern which promotes reuse and allows integration of diverse software components