'Adapter Pattern'에 해당되는 글 1

  1. 2007/09/29 Comparison between Object adapter and Class adapter
전공 | Posted by kimgisa.net 2007/09/29 16:56

Comparison between Object adapter and Class adapter

Comparison between Object adapter and Class adapter

Structure

A class adapter uses multiple inheritance to adapt one interface to another:

사용자 삽입 이미지

An object adapter relies on object composition:


사용자 삽입 이미지


Consequences

Class and object adapters have different trade-offs.

A class adapter
- adapts Adaptee to Target by committing to a concrete Adapter class. As a consequence, a class adapter won't work when we want to adapt a class and all its subclasses.
- lets Adapter override some of Adaptee's behavior, since Adapter is a subclass of Adaptee.
- introduces only one object, and no additional pointer indirection is needed to get to the adaptee.

An object adapter

- lets a single Adapter work with many Adaptees—-that is, the Adaptee itself and all of its subclasses (if any). The Adapter can also add functionality to all Adaptees at once.
- makes it harder to override Adaptee behavior. It will require subclassing Adaptee and making Adapter refer to the subclass rather than the Adaptee itself.

[Reference] Design Patterns by GoF (p.141 Adapter Pattern)