👉 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);
}
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. EF Core already implements both (DbSet<T>, DbContext.SaveChanges). Adding them on top is optional. Pros: domain code doesn't reference EF, queries are centralised, testing is easier. Cons: extra layers, and generic repositories often leak IQueryable or limit EF features. A balanced answer: aggregate-specific repositories in DDD/Clean Architecture; direct DbContext usage in simpler apps, with integration tests using SQLite/Testcontainers.
Can you answer these?
- How is ASP.NET Core middleware an example of Chain of Responsibility?
- What is the Observer pattern and how does C# support it?
- Explain CQRS. When is it worth it?
- What is the Outbox pattern and why is it needed?
The answers, plus 12 more Design Patterns (GoF + Enterprise) in C# interview questions and a mock-interview mode, are free on DevLadder.
Next in the course: Decorator →
Top comments (0)