views:

76

answers:

1

Hi, I stumbled upon this class and was wondering if XYZAdapter might be the correct name. I know how the adapter pattern works, but this solution is a bit different: Instead of implementing the DataTable interface and mapping the appropriate method calls, im creating a new DataTable object by copying the values and expose this object. Thats how it looks:

class Adapter
{
    private NodeList list;
    DataTable table { get { return CreateTable(); } }

    Adapter(NodeList nl)
    {
        list = nl;
    }

    private DataTable CreateTable()
    {
        // Fetch Data in NodeList, create a Table and return it
        // needs to be splitted in smaller methods ;D
    }
}

Usually im doing it this way, but the DataTable interface is enormus:

class Adapter : DataTable
{
    private NodeList list;
    DataTable table { get { return CreateTable(); } }

    Adapter(NodeList nl)
    {
        list = nl;
    }
    // Here are all the DataTable methods mapped to NodeList
}

Thanks in advance!

+3  A: 

An adapter adapts a non-compliant interface into a compliant one. e.g. it transforms/wraps a circular peg to form a square peg, so that it fits a square slot.

Your solution is not technically the adapter pattern - it's more of a translator or a converter. The key difference being that your adapter cannot be substituted in methods expecting an instance of a DataTable.

Gishu
In fact, the first thing i did was google translator/converter pattern..
atamanroman