Adapter Design Pattern


 definition
 UML diagram
 participants
 sample code in C#


definition

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Frequency of use:   medium high

UML class diagram

participants

    The classes and/or objects participating in this pattern are:

  • Target   (ChemicalCompound)
    • defines the domain-specific interface that Client uses.
  • Adapter   (Compound)
    • adapts the interface Adaptee to the Target interface.
  • Adaptee   (ChemicalDatabank)
    • defines an existing interface that needs adapting.
  • Client   (AdapterApp)
    • collaborates with objects conforming to the Target interface.

sample code in C#

This structural code demonstrates the Adapter pattern which maps the interface of one class onto another so that they can work together. These incompatible classes may come from different libraries or frameworks.

Show code

// Adapter pattern -- Structural example




This real-world code demonstrates the use of a legacy chemical databank. Chemical compound objects access the databank through an Adapter interface.

Show code

// Adapter pattern -- Real World example




This .NET optimized code demonstrates the same real-world situation as above but uses modern, built-in .NET features.

Show code

// Adapter pattern -- .NET optimized




  • Better Code
  • Better Career
  • Better Lifestyle

Design Pattern
Framework 2.0
TM


In C# and VB.NET



Click here for details

-- Instant Access --
Instant Download