Class Adapter Pattern Code Review
Use the Class Adapter Pattern
Code Review
- Class Adapter Pattern Code Review: Define the Adapter Class, Adaptee Class and Target Interface
- Class Adapter Pattern Code Review: Use the Class Adapter Pattern
Code Walkthrough
The Program class creates various instances of the Adaptee class (object) and Adapter class (object).
class Program
{
static void Main(string[] args)
{
Adaptee first = new Adaptee( );
Console.Write("Before the new standard\nPrecise reading: ");
Console.WriteLine(first.SpecificRequest(5, 3));
ITarget second = new Adapter(); Console.Write("\nBefore the new standard\nPrecise reading (2): "); Console.WriteLine((second as Adaptee).SpecificRequest(5, 3));
ITarget third = new Adapter( ); Console.WriteLine("\nMoving to the new standard"); Console.WriteLine(third.Request(5));
Console.Read(); } }
ITarget second = new Adapter(); Console.Write("\nBefore the new standard\nPrecise reading (2): "); Console.WriteLine((second as Adaptee).SpecificRequest(5, 3));
ITarget third = new Adapter( ); Console.WriteLine("\nMoving to the new standard"); Console.WriteLine(third.Request(5));
Console.Read(); } }
First, an instance of the Adaptee class (object) is created and a direct method call is made on the class (object). Next, an instance of the Adapter class (object) is created and a similar call made on the class (object) as before.
Finally, an instance of the Adapter class is created and the adapted method is called.
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!