Skip to content

Instantly share code, notes, and snippets.

@biniama
Last active October 20, 2018 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biniama/57c730996a5e1ee7b88556f1fddf35ec to your computer and use it in GitHub Desktop.
Save biniama/57c730996a5e1ee7b88556f1fddf35ec to your computer and use it in GitHub Desktop.
Adapter vs Decorator vs Bridge
In scope and intent
Adapter - intent is to mix an interface into a class that doesn't currently implement htat interface.
Decorator - intent is to change the way a method behaves differently for different decorators.
Bridge - intent is to insolate sub-systems so you can swap out sub-systems without impacting the code that is using that sub-systems.
The point of a Bridge is to isolate two subsystems so that they can be independently modified. Bridges are big things, often comprised of other patterns (like Adapters and Decorators). This segment looks at how to implement a Bridge and discusses the differences between Bridge and similar patterns like Adapter.
E.g. JDBC (bad implementation of Bridge since swapping doesn't work as it should)
Best example: ORM systems like Hibernate.
Idea is to simplify
Facade is another way to isolate subsystems, but it's purpose is simplification, not complete isolation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment