Please enable JavaScript.
Coggle requires JavaScript to display documents.
Adapter aka Wrapper (Key Objects (Client - collaborates with objects that…
Adapter aka Wrapper
-
Applicability
-
You need to use several existing subclasses but it is impractical to adapt their interface by subclassing every one. An object adapter can can adapt the interface of the parent class
-
Related Patterns
-
-
Bridge - meant to separate interface from its implementation but Adapter - meant to change interface of existing object
Consequences
Using two-way adapters to provide transparency - Adapted object no longer conforms to adaptee interface, so can't be used as is where adaptee can be used. However this involves subclassing two different classes.
How much adapting should adapter do? - varies, can be just interface translation or could add more functionality
Applications
-
JPAVendorAdapter in Spring - allows to plug in vendor specific behavior in spring's EntityManagerFactory
Intent
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.
Motivation
When you have a class that you need to use but can't use it's interface. Create an adapter that will provide the functionality that the adapted class does not provide
Collaborations
Client calls methods on the adapter instance. In turn, the adapter calls methods on the adaptee instance
-
-