Member-only story
What is the Bridge Design Pattern?
Avoid unnecessary complexity with the Bridge Pattern

Sometimes important features of a class can — or even should — be developed independently. The Bridge helps us split code into smaller pieces and develop them separately. In this design pattern, we have two elements:
- abstraction
- implementation
Abstraction is the part that is used directly by the client. It also delegates jobs to the implementation. Imagine that we have an application that prepares HTML content for displays. Depending on the configuration of the display, we would like our content to look a bit different. All displays share the same interface:
<?php
namespace App\Structural\Bridge;
abstract readonly class Display
{
public function __construct(protected Content $content)
{
}
abstract public function render(): string;
}
Right now we have two different types. The standard one just shows the content.
<?php
namespace App\Structural\Bridge;
final readonly class Standard extends Display
{
public function render(): string
{
$html = $this->content->getHtml();
$css = $this->content->getCss();
return <<<CONTENT
$html;
<style>
$css
</style>…