Skip to content

Adaptor pattern

1、Adaptor pattern相对比较简单,结合具体例子是非常容易理解的,在"Example"章节中总结了一些例子

wikipedia Adapter pattern

Example

基于基础功能扩展出新的,所以adaptor pattern中,一定有一个underlying。

The Boost Graph Library (BGL)

custom-made (or even legacy) graph structures can be used as-is with the generic graph algorithms of the BGL, using external adaptation (see Section How to Convert Existing Graphs to the BGL). External adaptation wraps a new interface around a data-structure without copying and without placing the data inside adaptor objects. The BGL interface was carefully designed to make this adaptation easy.

C++ Input/output library

These abstract devices allow the same code to handle input/output to files, memory streams, or custom adaptor devices that perform arbitrary operations (e.g. compression) on the fly.

C++ STL stack

正如在design patterns used in STL(standard template library)回答中所说:

The STL stack is a container adapter.

C++\Pattern\Adaptor-pattern

其中给出了例子。