A comparison of the four wrapper patterns: Adapter (converts an interface), Decorator (same interface, adds behaviour), Proxy (same interface, controls access and lifecycle), Facade (new simpler interface over many classes), with .NET examples, a decision guide, and why mislabelling leads to misplaced logic such as duplicate retries.
All four wrap something, but for different reasons:
| Pattern | Interface | Wraps | Purpose |
|---|---|---|---|
| Adapter | Different from the wrapped type | One object | Convert it to what the client expects |
| Decorator | Same | One object | Add behaviour; stackable |
| Proxy | Same | One object | Control access: lazy creation, remoting, permissions |
| Facade | New, simpler | Many classes | Simplify a subsystem |
The quick test is three questions. Does the interface change? Is it one object or many? Does it add features or control access?
The distinction matters because it tells you where a responsibility belongs. Put retries in an adapter that already sits behind a resilience handler, and every failure is retried twice over.
"They all wrap something, so I tell them apart by why the wrapper exists, and two quick questions get you most of the way. First, does the interface change? An Adapter exposes a different interface from the thing it wraps: it converts Stripe's SDK into my
IPaymentGateway, or a byteStreaminto aTextReader. A Facade exposes a new, simpler interface, but over many classes rather than one:File.ReadAllTextAsyncover streams and encodings, or aPlaceOrderhandler over inventory, payments and shipping. Decorator and Proxy keep the same interface as what they wrap.Second, for the same-interface pair: does it add behaviour or control access? A Decorator adds a feature such as caching, metrics or compression, and you can stack several. A Proxy controls access to its subject. It might create the subject lazily, like EF Core's lazy-loading proxies, or it might stand in for something remote, like a gRPC client, or check permissions first. Structurally they're identical. The difference is intent, and the fact that a proxy often owns its subject's lifecycle, while a decorator is handed an object.
Why it matters: the pattern name tells the team what belongs in the class. The mistake I see is responsibilities ending up in the wrong wrapper. For example, at [company] someone added retries inside a payment adapter while the typed
HttpClientalready hadAddStandardResilienceHandler. Each failure was retried up to [three times three] attempts, and because the requests weren't idempotent, [some customers were charged twice]. Retry is a decorator-style concern that belongs in exactly one layer. The adapter should only translate. Agreeing on which wrapper you're writing is how you agree on what it's allowed to do."
| Adapter | Decorator | Proxy | Facade | |
|---|---|---|---|---|
| Interface vs wrapped | Different | Same | Same | New, simpler |
| Wraps | One object | One object | One object | A subsystem (many) |
| Intent | Convert | Add behaviour | Control access/lifecycle | Simplify |
| Stackable | Rarely | Yes | Sometimes | No |
| Creates the wrapped object | No | No | Often | Sometimes |
| .NET examples | StreamReader, TaskCompletionSource, Serilog provider |
GZipStream, BufferedStream, DelegatingHandler |
EF Core lazy proxies, gRPC stubs, Lazy<T> |
File.ReadAllTextAsync, HttpClient, DbContext |
| App example | StripePaymentGateway : IPaymentGateway |
CachedProductRepository |
AuthorisedDocumentStore |
PlaceOrderHandler |
| Question | Answer → pattern |
|---|---|
| Interface differs from the wrapped type, one object? | Adapter |
| New simplified interface over several classes? | Facade |
| Same interface, adds a feature? | Decorator |
| Same interface, controls when/whether/where the real object is used? | Proxy |
| Concern | Natural home |
|---|---|
| Unit/type/error translation | Adapter |
| Retry, caching, metrics, logging | Decorator (or DelegatingHandler), in one layer only |
| Authorisation, lazy creation, remoting | Proxy |
| Use-case orchestration | Facade / application service |
| Business rules | Domain model, never the wrapper |
A team found retries in three places for one outgoing payment call: inside the adapter, in a custom DelegatingHandler, and in AddStandardResilienceHandler. One transient 503 produced up to 27 attempts. After an incident review, the adapter was reduced to translation, the custom handler was removed, and idempotency keys were added. Duplicate charges dropped to zero and provider rate-limit errors fell by about 80%.
Checks conceptual precision across the structural patterns and whether the candidate uses that precision to put responsibilities in the right place.
Green flags
Red flags
Client ──▶ Wrapper ──▶ Wrapped
Every wrapper pattern is composition plus delegation. That's why intent is the only reliable way to tell them apart, and why the GoF book describes each pattern by its intent first.
RetryingPaymentGateway (decorator) → StripePaymentGateway (adapter) → Stripe SDK. Keeping them separate keeps each one single-purpose.CheckoutService
→ IPaymentGateway (MetricsDecorator: adds timing)
→ IPaymentGateway (StripePaymentGateway: Adapter, translates)
→ Stripe SDK → HttpClient (Facade over the handler chain)
→ DelegatingHandler (logging handler: Decorator)
→ ResilienceHandler (retry, breaker, timeouts: Decorator)
→ SocketsHttpHandler (real transport)
Each layer has one job. Retries happen in one place (the resilience handler); the adapter doesn't retry.
When a reviewer says "this is supposed to be an adapter, why does it make pricing decisions?", the pattern name gives a shared standard. ADRs that record "payment providers are adapters; resilience lives in the HTTP pipeline" prevent drift.
for (int attempt, Polly pipelines, AddStandardResilienceHandler) and check that each call path retries in exactly one layer.The four patterns side by side around one domain:
namespace Wrappers;
public interface IPaymentGateway
{
Task<PaymentResult> ChargeAsync(Guid orderId, decimal amountAud, CancellationToken ct);
}
// ADAPTER: different interface (vendor SDK) -> our interface; translation only, no retries
public sealed class StripePaymentGateway(Stripe.PaymentIntentService intents) : IPaymentGateway
{
public async Task<PaymentResult> ChargeAsync(Guid orderId, decimal amountAud, CancellationToken ct)
{
var pi = await intents.CreateAsync(
new Stripe.PaymentIntentCreateOptions { Amount = (long)(amountAud * 100m), Currency = "aud", Confirm = true },
new Stripe.RequestOptions { IdempotencyKey = orderId.ToString() }, cancellationToken: ct);
return new PaymentResult(pi.Status == "succeeded", pi.Id, pi.Status);
}
}
// DECORATOR: same interface, adds a feature (metrics), given its inner object
public sealed class MeteredPaymentGateway(IPaymentGateway inner, PaymentMetrics metrics) : IPaymentGateway
{
public async Task<PaymentResult> ChargeAsync(Guid orderId, decimal amountAud, CancellationToken ct)
{
using var _ = metrics.MeasureCharge();
return await inner.ChargeAsync(orderId, amountAud, ct);
}
}
// PROXY: same interface, controls access (and creates the real gateway lazily)
public sealed class RestrictedPaymentGateway(Lazy<IPaymentGateway> real, ICurrentUser user) : IPaymentGateway
{
public Task<PaymentResult> ChargeAsync(Guid orderId, decimal amountAud, CancellationToken ct) =>
user.HasPermission("payments.charge")
? real.Value.ChargeAsync(orderId, amountAud, ct)
: throw new UnauthorizedAccessException("Missing payments.charge permission.");
}
// FACADE: new, simpler interface over several subsystems
public sealed class CheckoutFacade(IInventory inventory, IPaymentGateway payments, IShipping shipping)
{
public async Task<string> PlaceOrderAsync(Cart cart, CancellationToken ct)
{
await inventory.ReserveAsync(cart.Lines, ct);
await payments.ChargeAsync(cart.OrderId, cart.Total, ct);
return await shipping.BookAsync(cart.OrderId, ct);
}
}
// Program.cs: retries live in ONE place, the HTTP pipeline, not in the adapter
// builder.Services.AddHttpClient("stripe").AddStandardResilienceHandler();
// builder.Services.AddScoped<StripePaymentGateway>();
// builder.Services.AddScoped<IPaymentGateway>(sp => new MeteredPaymentGateway(
// sp.GetRequiredService<StripePaymentGateway>(), sp.GetRequiredService<PaymentMetrics>()));
PaymentAdapterDecoratorProxy). Why it is wrong: Names describe mechanics, not purpose. Instead: Domain names (StripePaymentGateway, CachedProductRepository), with the pattern in docs or reviews.In practice the four wrappers stack around every external call, and the senior skill is keeping one responsibility per layer. Most production bugs I've seen with wrappers aren't about misnaming; they're about a responsibility living in two layers (double retries, double logging) or in the wrong one (business rules in a facade, caching outside authorisation).
| Question in review | Red flag |
|---|---|
| Does this adapter do anything except translate? | Retries, caching, rules inside it |
| Is this decorator's position in the chain deliberate? | Cache outside auth or tenant filtering |
| Does this proxy hide expensive work? | Lazy loading in a loop, remote call without timeout |
| Is this facade only orchestrating? | Validation and rules, 10+ dependencies |
I write the layering for outgoing calls into an ADR (adapter translates; resilience in the HTTP pipeline; metrics as a decorator) and check new integrations against it.
Adapter converts the interface of an existing class into the interface your code expects, without changing either side. It's a translator.
For a payment SDK, I define IPaymentGateway in my domain's terms. A StripePaymentGateway adapter then turns it into SDK calls, translating types and units (decimal AUD to cents), statuses and vendor exceptions into domain results. That keeps vendor types out of the codebase, lets tests use a fake, and confines a provider change to one class.
The trade-off is an extra layer. Keep it thin: an adapter translates, and business rules don't belong in it.
A Proxy has the same interface as the real object and controls access to it:
Lazy<T>, and EF Core lazy-loading proxies that load a navigation on first access..NET builds proxies at run time. EF Core generates subclasses through Castle, so navigations must be virtual. DispatchProxy creates interface proxies through Invoke(MethodInfo, args), but it uses Reflection.Emit and so isn't AOT-friendly. Castle DynamicProxy powers Moq and NSubstitute.
The trade-off is invisible behaviour. Code that looks like a property read can run a query (N+1), throw after the context is disposed, or make a network call.
How to tell it (STAR)
**S:** At [company] a payment provider brownout turned into double charges for [some] customers. **T:** I led the incident review and had to stop it recurring. **A:** One order's trace showed up to [27] attempts: our adapter retried, a custom handler retried, and the standard resilience handler retried, all nested. And there was no idempotency key, so timed-out requests became new charges. We switched off two of the layers and refunded customers, then reduced the adapter to pure translation, kept one retry layer, added idempotency keys, and wrote the layering into an ADR. **R:** Duplicate charges went to [zero], provider rate-limit errors fell by [~80%], and the attempt-count test has blocked one regression since.
Last updated 18 Nov 2026.