(I'm going to add something similar to the Wikipedia sample here ...)
Let's say you had a requirement to provide an IDeque<T> interface for some library with the following signature:
public interface IDeque<T> { void PushFront(T element); T PopFront(); void PushBack(T element); T PopBack(); int Count { get; } }
This can be easily implemented using a class in BCL-LinkedList <T>, but the specific interface required here will not match. To implement this interface, you need to provide an adapter - a class that executed the required interface using some other incompatible interface. It will look something like this:
public class Deque<T> : IDeque<T> { LinkedList<T> list = new LinkedList<T>(); public void PushFront(T element) { list.AddFirst(element); } public T PopFront() { T result = list.First.Value; list.RemoveFirst(); return result; }
In this case, you simply use the existing class (LinkedList <T>), but you wrap it in an adapter so that it can execute a different interface.
source share