In this article we would like to implement an Adaptor Design Pattern in three ways. This is not the right article to understand the fundamentals of the Adaptor Design Pattern but if you are already familiar with the concept then you can understand the implementation in this article.
Fine, the Adaptor Design Pattern has evolved to communicate to various classes through a single class. The traditional way is to implement a single interface in all classes and from the adaptor class we call the specific function with the help of an instance of an interface.
In the following example, we have implemented the same concept.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.Collections.ObjectModel;
namespace AdaptorTest
{
public interface ILaptop
{
void ShowBrand();
}
public class hp :ILaptop
{
public void ShowBrand()
{
Console.WriteLine("Charging to HP Laptop");
}
}
public class Compaq : ILaptop
{
public void ShowBrand()
{
Console.WriteLine("Charging to compaq Laptop");
}
}
public class laptopAdaptor
{
public static void makeCharge(ILaptop Obj)
{
Obj.ShowBrand();
}
}
class Program
{
static void Main(string[] args)
{
laptopAdaptor.makeCharge(new hp());
laptopAdaptor.makeCharge(new Compaq());
Console.ReadLine();
}
}
}
Here is sample output.

Now, in this example, we will implement the same concept in various ways. Here the “laptopAdaptor” class is a generic class and we have allowed the generic class to create an object of those classes that have implemented an ILpaptop interface.
Have a look at the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.Collections.ObjectModel;
namespace AdaptorTest
{
public interface ILaptop
{
void ShowBrand();
}
public class hp :ILaptop
{
public void ShowBrand()
{



Join the conversation! Your thoughts help the community grow.