Class Adapter Pattern Code Review

Define the Adapter Class, Adaptee Class and Target Interface

Code Download

Code Review

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.