Posted on August 26, 2007 @ 20:39
“The Adapter Pattern converts the interface of a class into another interface the clients expect.
Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.” - Head First Design Patterns
** Head First Design Patterns (Head First)**
by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra
If you’re trying to build a presentation layer that is platform agnostic, you might turn to adapters for simple UI controls.
For example in ASP.NET there is a drop down list control, and in Win Forms there is the Combo Box control.
A quick an easy adapter to the two controls might look like:
Each drop down list item might look like:
A concrete implementation for a Win Forms application might look like:
A concrete implementation for a ASP.NET application might look like:
And voila… we can write a presentation layer that binds data to an IDropDownListAdapter, without having to be specific to WinForms, ASP.NET, WPF, Silverlight etc.