Design Patterns - Structural Patterns (Comparison)
Decorator
Decorator pattern extends behavior by decorating component.
Strategy (Behavioral)
The intent of the Strategy pattern is to define a set of algorithms or a family of algorithms where you can exchange one of the algorithms for the other you can vary the algorithms independently from the context of the things that uses the algorithms.
Adapter
Adapter pattern adapts from one interface to another interface you want to use a particular interface but the thing that you want to use has a different interface you stick and adapter in between so that you can use the thing you want to use.
Proxy
Proxy controls access while the adapter says I only change the interface, I don’t want to change implementation. The proxy says I change the implementation but I don’t want to change interface. So, the proxy is a thing but uses the same interfaces so you can place the proxy instead of the thing that you wanted to use because it has the same interface it’s interchangeable but then the proxy controls access to that things that you placed it in front of.
Facade
Facade has none of this dependency injection or that stuff. The facade is a term that we use simply when you have a scenario where you have complex subsystem and then you throw a facade in between you say here’s the wall use this simpler thing and this simpler thing will interact with all that complexity from the subsystem and again this is not the same as proxy because it doesn’t necessarily require the facade to have the same interface as anything in the subsystem and it’s not the same as the adapter because it doesn’t necessarily adapt from one interface to another it. I mean the facade has a single interface but the subsystem might have a bazillion interfaces. So it’s simply a way of hiding some complexity of some subsystem.
Bridge
The Bridge pattern is perhaps actually most easily thought of as an extension of the strategy pattern. It’s like the strategy pattern but where the context that uses the strategy also is an inheritance hierarchy or also is a polymorphic hierarchy so you have two inheritance hierarchy or two polymorphic hierarchies and one of the hierarchies uses things from the other hierarchies so you can take anything from the first hierarchy and pair it up with anything from second hierarchy and that’s a valid pair so in some sense it’s a way of avoiding duplication of code and increasing reusability.