π Read the full lesson on DevLadder (free, lesson 6 of 18 in the Design Patterns (GoF + Enterprise) in C# course)
Convert one interface into another that clients expect: wrap a legacy or third-party API.
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 ) ; }
Enter fullscreen mode
Exit fullscreen mode
Benefits: the vendor SDK is isolated in one class, so switching providers or mocking in tests is easy.
An interview question on Design Patterns (GoF + Enterprise) in C
Explain the Repository and Unit of Work patterns. Do you need them with EF Core?
A Repository hides data access behind a collection-like interface; Unit of Work groups changes into one transaction.β¦