Design Patterns Bridge Pattern - Design Patterns

What is Design Pattern Bridge Pattern?

Connection is used when we need to decouple a concept from its implementation so that the two can vary separately. This type of design pattern comes under structural pattern as this pattern decouples implementation class and summary class by providing a bridge structure between them.

This pattern involves an interface which acts as a bridge which makes the functionality of concrete class’s independent from interface implementer classes. Both types of classes can be transformed structurally without moving each other.

We are representing use of Bridge pattern via following instance in which a circle can be drawn in different colours using same abstract class process but different bridge implementer course.

Implementation

We have a DrawAPI interface which is temporary as a bridge implementer and concrete classes Red Circle, Green Circle implementing the DrawAPI interface. Shape is a summary class and will use entity of DrawAPI. BridgePatternDemo, our assembly class will use form class to draw changed collared circle.
bridge_pattern_uml_diagram

Step 1

Construct bridge implementer interface.

DrawAPI.java

Step 2

Create concrete bridge implementer classes implement the DrawAPIinterface.

RedCircle.java

GreenCircle.java

Step 3

Form an abstract class form using the DrawAPI interface.

Shape.java

Step 4

Create concrete class implementing the Shape interface.

Circle.java

Step 5

Apply the Shape and DrawAPI classes to draw dissimilar collared circles.

BridgePatternDemo.java

Step 6

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Design Patterns Topics