SOLID & Design Patterns Interview Question #108
What is the Ports and Adapters pattern?
Architectural Patterns, Application Boundaries & Distributed Design Patterns Senior Advanced
Quick Interview Answer
Ports and Adapters separates the application core from external technologies. A port describes how the core communicates with the outside world, while an adapter connects that port to a specific technology.
Detailed Explanation
Ports and Adapters separates the application core from external technologies. A port describes how the core communicates with the outside world, while an adapter connects that port to a specific technology.
Inbound ports represent operations offered by the application. Outbound ports represent capabilities the application requires, such as persistence or external messaging.
Code Example
// Outbound port
public interface IPaymentGateway
{
Task ChargeAsync(Money amount);
}
// Adapter
public class StripePaymentGateway : IPaymentGateway
{
}