The Adapter pattern converts one interface into another so two otherwise incompatible types can work together, while the Decorator pattern wraps an object to add new behavior without changing its interface. They are both structural patterns that use wrapping, but they solve different problems.
Key Points: • Adapter's goal is interface compatibility; Decorator's goal is behavior enhancement. • Adapter typically wraps one incompatible object and translates calls to a different interface. • Decorator wraps an object that already implements the same interface it exposes. • Decorators can be stacked to layer multiple enhancements; adapters are usually a single translation layer. • Adapter is often introduced when integrating legacy or third-party code; Decorator is introduced during normal application design.
Example: An Adapter might let a PaymentGatewayV1 client work against a new PaymentGatewayV2 library by translating method calls, whereas a Decorator might wrap a Coffee object with a MilkDecorator and SugarDecorator to add cost and description without touching the Coffee class.
Interview Tip: A concise interview answer is:
"Adapter and Decorator both wrap an object, but Adapter changes the interface to make two incompatible types work together, while Decorator keeps the same interface and adds new behavior on top of the wrapped object. I use Adapter for integration problems and Decorator for extending functionality."