Over a million developers have joined DZone.

The Bridge Pattern

· Java Zone

Discover how AppDynamics steps in to upgrade your performance game and prevent your enterprise from these top 10 Java performance problems, brought to you in partnership with AppDynamics.

Description:

Decouples abstraction from implementation. Inheritance tightly couples an abstraction with an implementation at compile time. The Bridge pattern can be used to avoid binding between abstraction and implementation and to select the implementation at runtime.

decouple an abstraction from its implementation so that the two can vary independently”.

Example:

If you have a Car hierarchies of classes ,it can become extremely big like in the below diagram.

Benefits:

  • Defines class hierarchies consisting of primitive objects and composite objects
  • Makes it easier to add new kinds of components
  • Provides flexibility of structure and a manageable interface

When to use:

  • You want to represent the whole hierarchy or a part of the hierarchy of object
  • You want clients to be able to ignore the difference between compositions of objects and individual objects
  • The structure can have any level of complexity and is dynamic.

Diagram:

Or

The Java Zone is brought to you in partnership with AppDynamics. AppDynamics helps you gain the fundamentals behind application performance, and implement best practices so you can proactively analyze and act on performance problems as they arise, and more specifically with your Java applications. Start a Free Trial.

Topics:

Published at DZone with permission of Cristian Chiovari , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}