What are the two types of adapters (class and object adapters), and how do they differ?

Class adapters use multiple inheritance to adapt an interface by extending both the target and the adaptee, while object adapters use composition, holding a reference to an adaptee instance and delegating calls to it through the target interface.

Key Points: • Class adapters rely on inheriting from the adaptee, which Java doesn't directly support for classes since it lacks multiple class inheritance. • Object adapters hold a reference to an adaptee instance and implement the target interface by delegating to it. • Object adapters are more flexible because they can adapt any subclass of the adaptee at runtime, not just one fixed class. • Class adapters can override adaptee behavior more directly since they inherit it, but at the cost of tighter coupling. • In Java, object adapters (composition) are the practical default because Java classes can only extend one superclass.

Example: A class adapter in a language with multiple inheritance might extend both Target and Adaptee directly, while a Java object adapter instead implements Target and stores a private Adaptee field, forwarding calls to it inside the overridden Target methods.

Interview Tip: A concise interview answer is:

"Class adapters use inheritance to adapt an interface by extending both the target and adaptee, while object adapters use composition, holding an adaptee reference and delegating to it. Java favors object adapters since it doesn't support multiple class inheritance, and composition is also more flexible since it can work with any adaptee subclass."