trainingtrains Logo

91-9990449935

 0120-4256464

Bridge Pattern

A Bridge Pattern says that just "decouple the functional abstraction from the implementation so that the two can vary independently".

The Bridge Pattern is also known as Handle or Body.

Advantage of Bridge Pattern

  • It enables the separation of implementation from the interface.
  • It improves the extensibility.
  • It allows the hiding of implementation details from the client.

Usage of Bridge Pattern

  • When you don't want a permanent binding between the functional abstraction and its implementation.
  • When both the functional abstraction and its implementation need to extended using sub-classes.
  • It is mostly used in those places where changes are made in the implementation does not affect the clients.

Example of Bridge Pattern

The UML given below describes the example of bridge pattern.

UML for Bridge Pattern:

UML of Bridge Pattern

Implementation of above UML:

Step 1

Create a Question interface that provides the navigation from one question to another or vice-versa.

Step 2

Create a JavaQuestions implementation class that will implement Question interface.

Step 3

Create a QuestionManager class that will use Question interface which will act as a bridge..

Step 4

Create a QuestionFormat class that will extend the QuestionManager class

Step 5

Create a BridgePatternDemo class.


Output

Next TopicComposite Pattern