What is the Adapter Design Pattern in C Sharp .Net ?
Article 2 on design patterns-
The Adapter Design Pattern
The Adapter Design Pattern is a structural design pattern that converts the interface of a class into another interface that clients expect. It is used when two incompatible interfaces need to work together. Here is an example of the Adapter Design Pattern in C#:
using System;
public interface ITarget
{
void Request();
}
public class Adaptee
{
public void SpecificRequest()
{
Console.WriteLine("Adaptee method called.");
}
}
public class Adapter : ITarget
{
private readonly Adaptee _adaptee;
public Adapter(Adaptee adaptee)
{
_adaptee = adaptee;
}
public void Request()
{
_adaptee.SpecificRequest();
}
}
class Program
{
static void Main()
{
Adaptee adaptee = new Adaptee();
ITarget target = new Adapter(adaptee);
target.Request();
Console.ReadKey();
}
}
You may also like: Gmail Password Bhool Gaye Aur Recovery Number Bhi Band Hai? Account Kaise Kholein
- Part 1What is repository design pattern c# | design pattern in c# | C# interview question for experienced person
- Part 2What is the Prototype Design Pattern in C Sharp .Net ?
- Part 3What is the Facade Design Pattern in C Sharp .Net ?
- Part 4What is the Command Design Pattern in C Sharp .Net ?
- Part 5What is the Observer Design Pattern in C Sharp .Net ?
- Part 6What is the Adapter Design Pattern in C Sharp .Net ? (you are here)
- Part 7What is the Singleton Design Pattern in C Sharp .Net ?
- Part 8Design Patterns in C Sharp .Net with examples | Singleton Design Patterns
- No part matches your search.
Leave a Reply
Please log in to comment on this post.