0

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.

  • 2
    what is that you specifically find confusing in Wikipedia articles on Adapter and Delegation patterns? – gnat Dec 22 '15 at 21:36
3

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.

  • Thanks for your reply. But what I am thinking is, we are hiding class from the client with the help of intermediate class. But that could be done by the client and target class direct interaction ? – Muztaba Hasanat Dec 22 '15 at 21:50
  • @MuztabaHasanat Yes. Normally you would just let your "real" classes talk to each other directly. These patterns should only be introduced when you have a problem that they happen to solve. – Ixrec Dec 22 '15 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.