How do you tell the Bridge pattern apart from the Strategy pattern when both involve a class holding a reference to an interface it delegates to?
Structurally, the two can look identical -- a class holds a field typed as an interface, and calls methods on it instead of implementing that behavior itself. The distinction is about intent and about how many hierarchies are actually varying, not about the shape of the code. Strategy is about swapping one algorithm for a single class -- there is one hierarchy of concrete types, and the interface field is the only axis of variation. Bridge is about letting two entire class hierarchies, each with their own family of subclasses, vary independently of each other, connected only through that one composition link. If you find two independent dimensions of variation that both need their own subclasses -- like remote types and device types -- that is the signal you are looking at Bridge rather than Strategy.
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