3

So far as I know, there are two forms of the Adapter Pattern: the class adapter and the object adapter. Could someone please explain to me the following limitation of the class adapter and why it is not a limitation of the object adapter:

  • a class adapter is not suitable when we want to adapt a class and all of its subclasses.

I guess the following is considered a limitation of the object adapter:

  • with an object adapter it is harder to override Adaptee behaviour than with a class adapter.

Why is that?

gnat
20.5k29 gold badges117 silver badges308 bronze badges
asked May 15, 2014 at 12:36

1 Answer 1

2

A class adapter IS a subclass, so you certainly shouldn't use it to adapt multiple subclasses. Even assuming that multiple inheritance is available in your language of choice, this would create an unmaintainable chain of inheritance.

An object adapter wraps an object and thus can't be used to modify the behaviour of the class of the object it's wrapping. It can, however, decide how to use that behaviour.

answered May 15, 2014 at 12:51
2
  • could you give an example of an unmaintainable chain of inheritance I don't quite follow, please forgive me Commented May 15, 2014 at 13:18
  • Are you familiar with the diamond problem with multiple inheritance? If you have multiple subclasses, it becomes multiple diamonds linked together. I like to think of it as a rope ladder. This occurs several places with multiple inheritance (even with interfaces like in Java/C#) and can make a class hierarchy really difficult to grok. Commented May 15, 2014 at 15:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.