The Pluggable Adapter Design Pattern

Introduction

An object contains methods and variables. Methods can be invoked. Variables can be updated. But what if a variable contained a method? This would mean we could change the method dynamically. Several instances of the same class could have different methods in the same variable. In a sense, the pluggable adapter pattern takes polymorphism (the ability of override a method in a subclass) and the Strategy Design Pattern (the ability to change the algorithm used by a method) to a new level.

Structure

The key to the Pluggable Adapter Pattern is to be able to treat methods as data. (This is one of the big ideas behind the Functional Programming paradigm.) For example, we might represent methods as instances of a Method class:

Discussion

Java reflection provides a Method class. C++ functors can be pluggable adapters as can function pointers.