Adapter Pattern #7
-
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. with an object adapter it is harder to override Adaptee behaviour than with a class adapter. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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. |
Beta Was this translation helpful? Give feedback.
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.