Bridge Pattern


Bridge Pattern

Builder pattern provides independence to the interface from its implementation. It provides flexibility to both to vary independently.

Builder pattern provides independence to the interface from its implementation. It provides flexibility to both to vary independently.

Bridge Pattern


Builder pattern provides independence to the interface from its implementation. It provides flexibility to both to vary independently. Suppose we have a database containing multiple questions and we want to display the questions on the basis of the user selections. Then such type of problems can be solved with the Bridge Design Pattern. It does that simply by decoupling the relationship among the objects. 

Benefits: It separates the abstraction from the implementation details. Inheritance tightly couples the abstraction with the implementations at the compile time, However the Bridge pattern hides the implementation details, improves the extensibility, shares an implementation among multiple objects. It reduces the number of subclasses, sometimes use of pure inheritance increases the number of subclasses. It also improves the extensibility by extending independency between the abstraction and the implementation.

Usage: It is used in such situation if you do not want the permanent binding between an abstraction and its implementation. It is  frequently used in those places where changes made in the implementation does not effects the clients. It can be used to fulfill such requirements where the abstractions and the implementations needs to be extensible.

Now lets take an example:
First develop a interface : :

interface Question {

public void nextQuestion();
public void priorQuestion();
public void newQuestion(String q);
public void deleteQuestion(String q);
public void displayQuestion();
public void displayAllQuestions();


Develop another class QuestionManager implementing the interface : 

class QuestionManager {

protected Question questDB;
public String catalog;

public QuestionManager(String catalog) {
this.catalog = catalog;

public void next() {

public void prior() {

public void newOne(String quest) {

public void delete(String quest) {

public void display() {

public void displayAll() {
System.out.println("Question Catalog: " + catalog);


Develop another class QuestionFormat extending the QuestionManager class

class QuestionFormat extends QuestionManager {

public QuestionFormat(String catalog){

public void displayAll() {



Develop another class JavaQuestions implementing the "Question" interface :

import java.util.*;

class JavaQuestions implements Question {

private List <String> questions = new ArrayList<String>();

private int current = 0;

public JavaQuestions() {
questions.add("What is Java? ");
questions.add("What is marker interface? ");
questions.add("What is cross-platform? ");
questions.add("How multiple polymorphism 
   is achieved in java? "
questions.add("How many types of exception
   handling are there in java? "
questions.add("Define the keyword final for 
   variable, method, and class
   in java? "
questions.add("What is multi-tasking? ");
questions.add("What is multi-threading? ");


public void nextQuestion() {
if( current <= questions.size() - )

public void priorQuestion() {
if( current > )

public void newQuestion(String quest) {

public void deleteQuestion(String quest) {

public void displayQuestion() {
System.out.println( questions.get(current) );

public void displayAllQuestions() {
for (String quest : questions) {


Develop another class TestBridge. 

class TestBridge {

public static void main(String[] args) {

QuestionFormat questions = new QuestionFormat
"Java Language");

questions.questDB = new JavaQuestions();
// questions.questDB = new CsharpQuestions();
// questions.questDB = new CplusplusQuestions();


questions.newOne("What is polymorphism? ");
questions.newOne("How many types of polymorphism 
  are there in java?"



Here is the output of the above program:

C:\ Command Prompt 
C:\> javac
C:\> java TestBridge
What is Java? 

Question Catalog: Java Language
What is Java? 
What is marker interface? 
What is cross-platform? 
How multiple polymorphism is achieved in java? 
How many types of exception handling are there in java? 
Define the keyword final for variable, method, and class in java? 
What is multi-tasking? 
What is multi-threading? 
What is polymorphism? 
How many types of polymorphism are there in java?

The above example tries to show how the Bridge pattern pattern decouples the interface from its implementation. One can easily notice that the class JavaQuestion can be launched independently working as an independent system.