Class Adapter Pattern Code Review
Define the Adapter Class, Adaptee Class and Target Interface
Code Download
- Download Description:class adapter pattern download
- .NET Framework:3.5
- .NET Language:C#
- Date Published:2009-07-01
- Download Size:7 KB
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
Define the ITarget interface which defines the class structure that the client will use.
interface ITarget
{
String Request (Int32 i);
}
The Adaptee class (object) represents the class, in which the behaviour will be modified by the Adapter class (object).
class Adaptee
{
public double SpecificRequest (Double a, Double b)
{
return a/b;
}
}
The Adapter class (object) inherits behaviour from both the ITarget interface and the Adaptee class.
class Adapter : Adaptee, ITarget
{
public String Request(Int32 i)
{
return "Rough estimate is " + (Int32)Math.Round(SpecificRequest(i, 3));
}
}
The Request() method wraps the call to the Adaptee method modifying the output for the client.
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!