- works as adapter between two incompatible interfaces
- Convert the existing interfaces to a new interface to achieve compatibility and
- re-usability of the unrelated classes in one application
- Convert the interface of a class into another interface clients expect
- Also known as Wrapper pattern
- Make unrelated classes work together
- Multiple compatibility
- Achieve the goal by inheritance or by composition.
Implementation example
- Interface Connectivity declares basic method to provide connectivity in mobiles
- Class Bluetooth implements Connectivity
- Client uses Bluetooth class
In order to support NFC also, create an adapter :
- Create another class ConnectivityAdapter implementing Connectivity interface
- Class ConnectivityAdapter will use existing Bluetooth class and another classes providing NFC functions
- Client can now use ConnectivityAdapter instead of Bluetooth
No comments:
Post a Comment
Note: only a member of this blog may post a comment.