Search code examples
javadesign-patternsbridge

Bridge pattern in java without abstract class


I am trying to learn Bridge pattern. So far every page I have referred to, has one abstraction as interface and other as abstract class. Abstract class holds a reference to interface. I was wondering, if I replace abstract class with interface and have a reference of second interface in each impl class, would that still make sense in context of Bridge pattern.


Solution

  • If you move the composition relationship from the abstract class down to its implementation, then you have an Adapter rather than a Bridge.

    If you have multiple Adapters all composing a common interface, then it probably makes sense to pull that composition relationship up to an abstraction, i.e. a Bridge again.

    See also: Adapter vs Bridge