Routine + Email
Email → Disk full
A notification service supports routine and urgent alerts, and can deliver each through email or SMS. Creating a separate class for every alert-and-channel pair grows the combinations and repeats delivery details.
This is a structural pattern lesson. Follow the responsibilities, inspect the small JavaScript example and compare the design choices. The example is local teaching code; its boundary is explained before you apply the idea to a real service.
Bridge separates the high-level behaviour from the implementation it uses. The high-level object holds an implementation through a contract and delegates work to it. The two dimensions can then gain variants independently.
Here Alert and UrgentAlert express message behaviour. EmailDelivery and SmsDelivery express delivery. UrgentAlert can use either implementation without becoming an UrgentEmailAlert and an UrgentSmsAlert hierarchy.
Read the JavaScript from top to bottom and compare the expected output. The values are chosen to make this pattern’s responsibility visible. This example runs in one local execution context; it does not create remote services, durable storage or production access controls.
JavaScript · local teaching example
class Alert {
constructor(delivery) { this.delivery = delivery; }
notify(text) { return this.delivery.send(text); }
}
class UrgentAlert extends Alert {
notify(text) { return super.notify('URGENT: ' + text); }
}
const email = {send: text => 'Email → ' + text};
const sms = {send: text => 'SMS → ' + text};
console.log(new UrgentAlert(email).notify('Disk full'));
console.log(new UrgentAlert(sms).notify('Disk full'));Expected output
Email → URGENT: Disk full
SMS → URGENT: Disk fullEmail → Disk full
SMS → Disk full
Email → URGENT: Disk full
SMS → URGENT: Disk full
Email → Disk full
This local composition does not send email or SMS. New channels must satisfy the delivery contract used by alert behaviours.
Choose routine or urgent behaviour, then email or SMS delivery. The matrix keeps all four supported combinations visible. The local result applies the same composition as the example; it does not send a real message.
Add a new channel by implementing send. Add an alert behaviour by delegating through that contract. Test both dimensions and their supported combinations.
Compare the visible consequences. With JavaScript enabled, choose an option in each scenario to assemble your decision record.
This is an exploratory design exercise. It does not run infrastructure, measure capacity or replace the lesson’s quiz.
Apply the pattern to two situations. Select one option in each situation to build a decision record. Every option and its consequence stays visible, and you can change your choices.
Use it when two real variation dimensions need independent extension, such as report formats and delivery channels. Keep the implementation contract narrow enough to support the high-level behaviours.
A bridge adds a delegation boundary and configuration responsibility. If there is only one stable dimension, direct composition or a Strategy can be clearer. Independent extension still requires compatible semantics and tests for supported combinations.
Adapter wraps an already mismatched interface. Strategy commonly swaps an algorithm within a behaviour. Bridge explicitly separates two independently extensible dimensions. The system/code distinction explains why this object structure does not by itself distribute the service.
Follow Adapter for an existing interface mismatch, Strategy for an interchangeable algorithm, compatible implementation families to compare the specific responsibility before combining patterns.
For further reading, use the Bridge reference supplied for this course. Compare it with this original example and the guarantee required by your application.
For Bridge, describe the problem, the participating roles and the observable contract. Use the example as a starting point and test the boundaries identified in the trade-offs. A pattern name alone does not establish correctness or performance.
Return to the design-pattern guide to compare families, or apply the idea alongside compatible implementation families.
Reaching the recap and completing the quizzes are separate milestones.