Desing Patterns in Golang: Bridge

Introduction

The Bridge Pattern is a creational design pattern used to decouple an
abstraction from its implementation. The bridge uses encapsulation,
aggregation, and can use inheritance to separate responsibilities into
different classes.

Purpose

Decouple an abstraction from its implementation that allows both to vary independently.

Publish interface in an inheritance hierarchy, and bury implementation in its own inheritance hierarchy.

Design Pattern Diagram

The objects participating in this pattern are presented on the following diagram:

Abstraction defines the abstraction’s interface and maintains a reference to an object of type Implementor

RefinedAbstraction extends the interface defined by Abstraction

Implementor defines the interface for implementation objects

ConcreteImplementor implements the Implementor interface and defines its concrete implementation

Implementation

Consider building an UI package that supports drawing different shapes on the
screen by supporting OpenGL and Direct2D rendering technologies. In our
particular example should be able to draw a circle by supporting both rendering
systems.

In order to do that we should separate the Circle struct from its drawing
implementation: