Menu

Adapter (Design Patterns)
πŸ“°

Adapter (Design Patterns)

DEV Community: dotnetΒ·DIVAKAR UPADHYAYΒ·7 days ago
#6bqrKez9
#devtodotnet#devto#dev#string#patterns
Long article (311 words) β€” no AI summary yet.
Reading 0:00
15s threshold

πŸ‘‰ 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.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.