← All Quizzes
What is the Adapter pattern and when should it be used?
Explanation
The Adapter pattern is a structural design pattern that allows objects with incompatible interfaces to collaborate. It acts as a wrapper: it wraps an object with a new interface that the client expects, translating calls from the new interface to the original. Use Adapter when: integrating third-party libraries with different interfaces, reusing existing classes with incompatible interfaces, or migrating to a new interface gradually. Adapters can be class-based (inheritance) or object-based (composition, preferred). They enable legacy code integration without modification.