advancedBridge, Visitor & Chain of Responsibility

How does the Bridge pattern prevent the class explosion that happens when you model every combination of two independent hierarchies as its own class?

Modeling every combination directly, such as one class per remote-type-and-device-type pairing, needs N times M classes for N remote types and M device types -- 50 classes for just 5 remotes and 10 devices, with logic duplicated across every class sharing a device or a remote type. Bridge fixes this by recognizing that the two dimensions are genuinely independent and should never have been combined into one hierarchy at all. It splits them into two separate hierarchies -- an abstraction hierarchy and an implementation hierarchy -- and connects them through one composition reference held by the abstraction. That turns the class count from N times M into N plus M, which is 15 for the same 5-and-10 example, and the gap only widens as either dimension keeps growing.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What does double dispatch mean in the Visitor pattern, and how does it let a program run different logic per concrete type without any instanceof checks?← Back to all Low-Level Design & Design Patterns questions