Java Code Samples

Bridge

Posted in Old stuff by Cristian on May 9, 2011

Description:

Decouples abstraction from implementation.Inheritance tightly couples an abstraction with an implementation at compile time. 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

About these ads

One Response

Subscribe to comments with RSS.

  1. [...] Bridge [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: