Difference Between Adapter and Delegation Design Patterns

adapterdelegatesdesign-patterns

I am very confused about Adapter and Delegation design pattern. In Adapter pattern we bring an intermediate class to interact with another class. And in Delegation pattern we also bring an intermediate class to refer/interact with another class.

Best Answer

Structurally the two patterns are similar. But remember that design patterns are meant to be solutions to specific problems. The problems that Adapter and Delegation solve are quite different.

A typical problem for Delegation is when you go to implement a class, and realize that part of the implementation is quite complicated, and having a helper object to encapsulate a particular chunk of the implementation logic would make things significantly more readable.

A typical problem for Adapter is when you have two classes that do the same thing, but with different interfaces, yet you want your code to be able to work with both. So you decide which interface is better for your purposes, then write an adapter around the other class so that you can use it as if it had the better interface all along.

Related Topic