Bridge Pattern Tutorial
This tutorial is aimed to guide the definition and application of Gang of Four (GoF) bridge design pattern. By reading this tutorial, you will know how to develop a model for the bridge pattern, and how to apply it in practice.
Modeling a Design Pattern with a Class Diagram
- Create a new project called Design Patterns.
- Create a class diagram named Bridge.

- Select Class from the diagram toolbar. Click on the diagram to create a class. Name it Abstraction.

- Right-click on Abstraction and select Model Element Properties > Abstract to set it as abstract.

- Move the mouse cursor over the Abstraction class and drag out Aggregation > Class to create an associated class named Implementor.

- Right-click on Implementor and select Model Element Properties > Abstract to set it as abstract.
- Right-click on the Abstraction class and select Add > Operation from the popup menu.

- Name the operation Operation().
- Right-click on the Implementor class and select Add > Operation from the popup menu. Name the operation OperationImpl().

- Right-click on Implementor and select Model Element Properties > Abstract to set it as abstract.

- Move the mouse cursor over the Abstraction class and drag out Generalization > Class to create a subclass named RefinedAbstraction.

- Repeat the previous step to create a subclass named ConcreteImplementor from Implementor.

- ConcreteImplementor will inherit the operations from Implementor. Right-click on ConcreteImplementor and select Related Elements > Realize all Interfaces from the popup menu.

- In practice, there may be multiple refined abstractions and/or concrete implementors. To represent this, stereotype the RefinedAbstraction and ConcreteImplementor classes as PTN Cloneable. Right-click on Abstraction and select Stereotypes > Stereotypes... from the popup menu.

- In the Stereotypes tab of the Class Specification dialog box, select PTN Cloneable and click > to assign it to the RefinedAbstraction class. Click OK to confirm.

- Repeat steps 14 and 15 for ConcreteImplementor.

- In practice, there may be multiple operations and/or operationImpls. To represent this, stereotype the Abstraction and Implementor classes as PTN Members Creatable. Repeat steps 14 and 15 to stereotype Abstraction and Implementor as PTN Members Creatable.
Defining a Pattern
- Select all classes on the class diagram.

- Right-click on the selection and select Define Design Pattern... from the popup menu.

- In the Define Design Pattern dialog box, specify the pattern name as Bridge. Keep the file name as is and click OK to proceed.

Applying a Design Pattern to a Class Diagram
In this section, we will apply the bridge pattern to model a report generator for various report types.
- Create a new project named Diagram Editor.
- Create a class diagram named Domain Model.
- Right-click on the class diagram and select Utilities > Apply Design Pattern... from the popup menu.

- In the Design Pattern dialog box, select Bridge from the list of patterns.

- Click on Abstraction in the overview.

- Rename Abstraction to ReportGenerator and the Operation operation to generate in the bottom pane.

- Select RefinedAbstraction in the overview pane.
- Rename RefinedAbstraction to HTMLReportGenerator.

- In addition to the HTML report generator, we also need a Plain Text report generator. Click the + button in the bottom pane, next to Abstraction, and select Clone...

- Enter 1 as the number of classes to clone and click OK to confirm.

- Rename the cloned class, RefinedAbstraction2, to PlainTextReportGenerator.

- Select Implementor in the overview pane.
- Rename Implementor to ReportGeneratorImpl and OperationImpl to generateTOC.

- We need two more operations for generating the content and appendix. Click the + button and select New Operation... from the popup menu.

- In the Operation Specification dialog box, name the operation generateContent. Check the Abstract box at the bottom of the dialog.

- Repeat the previous steps to create another abstract operation named generateAppendix.

- Select ConcreteImplementor in the overview. Rename ConcreteImplementor to SimpleReportGeneratorImpl and the OperationImpl operation to generateTOC.

- Similar to RefinedAbstraction, we need another concrete implementor for generating complex reports. Click the + button and select Clone... from the popup menu.

- Enter 1 as the number of classes to clone and click OK to confirm.
- Rename the cloned class, ConcreteImplementor2, to ComplexReportGeneratorImpl, and the OperationImpl operation to generateTOC.

- Click OK to confirm. The diagram should now look like this:

- We want HTMLReportGenerator and PlainTextReportGenerator to implement their own way of generating reports. Select the "generate" operation in ReportGenerator.

- Press the Ctrl key and drag it to HTMLReportGenerator. Release the mouse button afterward.

- Repeat the previous steps to create the "generate" method in PlainTextReportGenerator. The completed diagram should look like this:
