Tutorials Design Patterns in C#
Bridge Pattern — Complete Guide
Bridge Pattern — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of Design Patterns in C# on Toolliyo Academy.
On this page
Design Patterns in C# · Lesson 7 of 69
Bridge Pattern
GoF Core → Enterprise → Cloud & Craft
GoF Core · 1 — Create & structure · ~6 min · Module 2: Structural Design Patterns
What is this?
Bridge splits abstraction from implementation so both can vary independently — e.g. notification type × sender transport.
Why should you care?
ShopNest “OrderPaidAlert” should work over Email or Slack without a class explosion.
See it live — copy this example
Paste into a C# console or class library project and run dotnet run.
public interface IMessageSender { void Send(string msg); }
public sealed class EmailSender : IMessageSender
{
public void Send(string msg) => Console.WriteLine($"email: {msg}");
}
public abstract class Alert
{
protected readonly IMessageSender Sender;
protected Alert(IMessageSender sender) => Sender = sender;
public abstract void Notify(string text);
}
public sealed class OrderPaidAlert : Alert
{
public OrderPaidAlert(IMessageSender sender) : base(sender) { }
public override void Notify(string text) => Sender.Send($"PAID {text}");
}
new OrderPaidAlert(new EmailSender()).Notify("Order 9");
Run Example »
Edit the code below and click Run to see the result in Toolliyo’s live editor.
What happened?
- Alert hierarchy is the abstraction; IMessageSender is the implementation.
- Mix OrderPaidAlert with SlackSender later without new subclasses for every pair.
Practice next
- Run OrderPaidAlert with EmailSender.
- Add SlackSender and reuse OrderPaidAlert.
- Add RefundAlert sharing the same senders.
- Inject IMessageSender via DI.
- Add SmsSender.
Remember
Abstraction ⟂ implementation. Avoid Cartesian subclass growth. Inject the implementor.
ShopNest alert bridge
Ops chooses Slack vs Email per environment.
Outcome: Same alert types; different transports.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!