Adapter
Intent
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
Class diagram of the original GoF pattern
Class adapter

Object adapter

Another solution in MixJuice
Solved Problem(s)
- Extensibility problem
- Object adapters make it impossible to override Adaptee behavior without modifying the source code of Adapter. It requires new subclass SubAdaptee and modifying Adapter so that it create an instance of SubAdaptee instead of Adaptee. (This problem is mentioned at p.142 lines 14-16 in the GoF book.)
- Complexity problem
- In order to adapt a class and all its subclasses using class adapters, each class to be adapted requires corresponding class adapter. (This problem is mentioned at p.140 lines 24-26 and p.143 lines 9-12 in the GoF book.)
Used programming technique(s)
Super-interface addition to Adaptee class.
Consequences
The followings are trade-offs between class adapters, object adapters and this solution. (See also p.142 in the GoF book that explains trade-offs between class and object adapters.)
- (+) This solution make it possible to adapt Adaptee itself and all subclasses of Adaptee.
- (+) This solution allows defining new subclass of Adaptee to override some of Adaptee's behavior.
- (+) This solution is simpler than class and object adapters. No additional classes and pointer indirections are introduced.
- (-) If Target is a class, not an interface, only object adapters are applicable; because multiple inheritance of classes are not supported by MixJuice.
- (-) Two-way adapters (p.143 lines 9-12 in the GoF book) are not applicable because multiple inheritance of classes are not supported by MixJuice.
Structure and pseudo code

module library {
define class Adaptee {
define void specificRequest() {...}
}
define class SubAdaptee extends Adaptee {...}
}
module application extends library {
define interface Target {
define void request();
}
class Adaptee implements Target {
void request() { specificRequest(); }
}
}
Akira TANAKA <akr@m17n.org>, Yuuji ICHISUGI <y-ichisugi@aist.go.jp>Top