Bridge intent (separate an abstraction from its implementation so both vary independently), avoiding M×N class explosions, notification types × channels in C#, ILogger over ILoggerProvider and HttpClient over HttpMessageHandler, and Bridge vs Adapter vs Strategy.
Bridge splits an abstraction from its implementation so the two can vary independently, linked by composition. It prevents class explosions: 4 message types Γ 3 channels would need 12 subclasses, but with a bridge it's 4 message classes plus 3 channel classes.
.NET has two well-known bridges:
ILogger β ILoggerProvider: what you log is separate from where it goes (console, OpenTelemetry, Application Insights).HttpClient β HttpMessageHandler: a friendly request API on one side, and the transport (SocketsHttpHandler, or a fake handler in tests) on the other.An Adapter is retrofitted to make an existing interface fit, whereas a Bridge is designed up front. A Strategy swaps one algorithm. The trade-off is an extra interface that only pays off when both dimensions really change.
"Bridge is about two dimensions that change independently. Without it you tend to model them with inheritance and get a class for every combination. Take notifications. We have message types like order shipped, password reset and invoice due, and channels like email, SMS and push. Model that with inheritance and you end up with
OrderShippedEmail,OrderShippedSms,PasswordResetEmailand so on: M times N classes. Adding WhatsApp means one new class per message type, and a bug fix in SMS formatting has to be repeated in each of them. With Bridge, the message side, the abstraction, builds the content, and it holds a reference to anIChannel, the implementor, that knows how to deliver it. Now it's M plus N classes, and the two sides grow separately.The framework's best examples are logging and HTTP.
ILoggeris the abstraction you code against: categories, levels,LogInformationand the source-generated[LoggerMessage]methods. Where the logs actually go is the implementor side:ILoggerProviderfor the console, OpenTelemetry or Application Insights. TheLoggerFactorybridges the two, so one log call reaches every provider, and you can add a provider without touching any logging call.HttpClientis the same shape. It offersGetFromJsonAsync, timeouts and headers, and delegates the actual sending to anHttpMessageHandler, which isSocketsHttpHandlerin production or a fake handler in tests.The mistake I see is using Bridge when only one dimension varies. Then it's just an extra interface. Compared with the neighbours: Adapter makes an existing, mismatched interface fit after the fact, and Strategy swaps a single algorithm inside one class. Bridge is a design decision you make up front to stop a class hierarchy multiplying."
| Approach | 4 message types Γ 3 channels | Add a channel | Add a message type |
|---|---|---|---|
| Inheritance per combination | 12 classes | +4 classes | +3 classes |
| Bridge | 4 + 3 = 7 classes | +1 class | +1 class |
| Abstraction (what) | Implementor (how/where) | Joined by |
|---|---|---|
ILogger<T> |
ILoggerProvider (Console, OpenTelemetry, App Insights) |
LoggerFactory |
HttpClient |
HttpMessageHandler (SocketsHttpHandler, fakes) |
Constructor / IHttpClientFactory |
DbContext + LINQ |
Database provider (SQL Server, PostgreSQL, SQLite) | UseSqlServer() etc. |
| Pattern | Intent | When designed |
|---|---|---|
| Bridge | Let two hierarchies vary independently | Up front |
| Adapter | Make an existing interface fit | After the fact |
| Strategy | Swap one algorithm in a context | Either |
A notification service had grown to 15 classes for 5 message types across 3 channels. Adding WhatsApp would have meant 5 more, and a privacy fix that masked phone numbers in SMS logs had been applied to only 3 of the 5 SMS classes. Refactoring to a bridge (message builders + IChannel) produced 8 classes, the masking fix lived in one place, and WhatsApp was one new channel class.
Checks whether the candidate understands Bridge's real purpose (two independent axes) and can recognise it in the framework rather than reciting a definition.
Green flags
ILogger/ILoggerProvider and HttpClient/HttpMessageHandler.Red flags
ILogger in a custom abstraction. Abstraction ββββββ holds βββββββΆ Β«interfaceΒ» Implementor
+ Send() + Deliver(content)
β² β² β² β²
RefinedAbstraction(s) EmailChannel SmsChannel PushChannel
OrderShippedNotification
PasswordResetNotification
The "bridge" is the reference from abstraction to implementor. Each side has its own hierarchy.
ILogger<OrderService> (the abstraction, with a category).LoggerFactory holds every registered ILoggerProvider. For a category it creates a Logger that wraps one ILogger per provider.logger.LogInformation(...) checks filters and levels, then calls each provider's logger.builder.Logging.AddOpenTelemetry(...)) adds a provider; no logging call changes.The abstraction side can also evolve independently: [LoggerMessage] source generation, scopes and structured templates work with every provider.
HttpClient is a bridgeHttpClient derives from HttpMessageInvoker, which holds an HttpMessageHandler. Every convenience method (GetStringAsync, PostAsJsonAsync) ends in SendAsync, which calls the handler. Swap the handler and the same client code sends over sockets, WinHTTP, an in-memory test server (WebApplicationFactory.CreateClient()), or a fake that returns canned responses.
If only one axis varies, a plain interface (Strategy) is enough.
In a DI world many bridges are just constructor injection: the abstraction takes the implementor interface. The pattern name matters less than the design decision: don't encode two axes in one inheritance tree.
HttpMessageHandler that returns a fixed JSON body and use it with a typed client in a unit test.ILoggerProvider that collects log entries in a list, register it alongside the console provider, and assert on entries in a test.XyzSqlExporter, XyzCsvExporter, AbcSqlExporter. Is it two axes in one tree?Notifications as a bridge: message kinds on one side, channels on the other:
namespace Notifications;
public sealed record Recipient(string Email, string? Mobile, string? PushToken);
public sealed record MessageContent(string Subject, string Body);
// Implementor: HOW a message is delivered
public interface IChannel
{
Task DeliverAsync(Recipient to, MessageContent content, CancellationToken ct);
}
public sealed class EmailChannel(IEmailSender email) : IChannel
{
public Task DeliverAsync(Recipient to, MessageContent c, CancellationToken ct) =>
email.SendAsync(to.Email, c.Subject, c.Body, ct);
}
public sealed class SmsChannel(ISmsSender sms, ILogger<SmsChannel> logger) : IChannel
{
public async Task DeliverAsync(Recipient to, MessageContent c, CancellationToken ct)
{
if (to.Mobile is null) return;
await sms.SendAsync(to.Mobile, c.Body[..Math.Min(160, c.Body.Length)], ct);
logger.LogInformation("SMS sent to {Mobile}", Mask(to.Mobile)); // one place for privacy masking
}
private static string Mask(string m) => m.Length <= 4 ? "****" : new string('*', m.Length - 3) + m[^3..];
}
// Abstraction: WHAT is said; holds the implementor (the bridge)
public abstract class Notification(IChannel channel)
{
protected abstract MessageContent Build();
public Task SendAsync(Recipient to, CancellationToken ct) => channel.DeliverAsync(to, Build(), ct);
}
public sealed class OrderShipped(IChannel channel, string orderNumber, string trackingUrl) : Notification(channel)
{
protected override MessageContent Build() =>
new($"Order {orderNumber} has shipped", $"Track it here: {trackingUrl}");
}
public sealed class PasswordReset(IChannel channel, Uri resetLink) : Notification(channel)
{
protected override MessageContent Build() =>
new("Reset your password", $"Use this link within 30 minutes: {resetLink}");
}
// Usage: any message over any channel
// await new OrderShipped(smsChannel, "A1001", url).SendAsync(customer, ct);
// await new PasswordReset(emailChannel, link).SendAsync(customer, ct);
// The framework bridge in a test: same HttpClient API, fake implementor
namespace Notifications.Tests;
using System.Net;
public sealed class StubHandler(HttpStatusCode code, string json) : HttpMessageHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct) =>
Task.FromResult(new HttpResponseMessage(code) { Content = new StringContent(json) });
}
// var client = new HttpClient(new StubHandler(HttpStatusCode.OK, "{\"status\":\"sent\"}")) { BaseAddress = new("https://sms.test") };
OrderShippedSms, OrderShippedEmail...). Why it is wrong: Classes multiply MΓN and fixes must be repeated in every combination. Instead: Split into two hierarchies joined by composition.ILogger "to decouple from Microsoft". Why it is wrong: ILogger is already the abstraction side of a bridge; another layer adds nothing. Instead: Code against ILogger and add providers.HttpClient directly. Why it is wrong: Its methods aren't virtual; tests become awkward. Instead: Use the bridge: a fake HttpMessageHandler.Bridge is the pattern that stops an inheritance tree from multiplying. In modern .NET it's mostly invisible: DI plus an interface on the implementor side gives you a bridge by default. The senior skill is spotting two axes of change hiding in one hierarchy and splitting them before the combinations explode.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
Single class with switch |
One axis, few cases | None | Cases keep growing |
| Strategy (one interface) | One axis varies | One interface | Two axes vary |
| Bridge (two hierarchies) | Two independent axes | Two hierarchies to understand | Only one axis really varies |
Framework bridge (ILogger, HttpMessageHandler) |
Logging, HTTP | None | Don't wrap it again |
A quick test: if adding one item on either axis forces you to create several classes, you have a missing bridge.
Default to composition: build behaviour from small objects behind interfaces and inject them. It keeps coupling low, lets behaviour change at run time and is easy to test. Use inheritance only when all of these hold: there is a true is-a relationship where every subtype can substitute for the base (Liskov), the base was designed for extension (documented virtual hooks, protected constructor), there is one axis of variation, and you want to share state plus a fixed algorithm (template method). Framework extension points such as BackgroundService, DelegatingHandler and DbContext are good inheritance cases. When a hierarchy explodes or subclasses override things to throw NotSupportedException, refactor by extracting the varying behaviour into strategies and composing them.
Choose an interface when you are defining a capability or contract that unrelated types may implement, when a type may need several such contracts, when structs must implement it, or when you need static abstract members for generic code. Choose an abstract class when implementers share state, constructor logic or a fixed algorithm, and when the type is an extension point that will grow, because you can add virtual members with bodies safely. Default interface methods narrowed the gap but cannot hold state, so they are mainly for evolving published interfaces. In libraries, a common pattern is both: consumers depend on the interface, and implementers can derive from an abstract base that does the plumbing.
How to tell it (STAR)
**S:** At [company] a privacy review found full mobile numbers in our logs, even though we had shipped a masking fix. **T:** I owned the notification service and had to close the leak and stop it happening again. **A:** The logging code was copied into five SMS classes, one per message type, and the fix had reached only three. I patched the other two and arranged the log purge, then refactored the service so message types build content and channels deliver it, with masking in exactly one place. **R:** The service went from [15] classes to [8], the leak was closed for every message type, and adding WhatsApp later took [one] class and [two days].
Last updated 18 Nov 2026.