Roadmap › Design Patterns (GoF + Enterprise) in C# › Module: Structural Patterns
Lessons in this course (18)
6. Adapter
Intermediate★ Must knowLesson 6 of 18
Convert one interface into another that clients expect — wrap a legacy or third-party API.
csharp
public interface ISmsSender { Task SendAsync(string phone, string text); } // our interface
public class TwilioSmsAdapter(TwilioRestClient client, string from) : ISmsSender // adapts the SDK
{
public Task SendAsync(string phone, string text) =>
MessageResource.CreateAsync(to: new PhoneNumber(phone), from: new PhoneNumber(from), body: text, client: client);
}Benefits: the vendor SDK is isolated in one class, so switching providers or mocking in tests is easy.