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!
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.