September 2016
Intermediate to advanced
270 pages
5h 16m
English
The Bridge pattern can be quite straightforward; it effectively allows us to decouple an abstraction from an implementation so the two can vary independently.
When classes vary frequently, bridging an interface and a concrete class allows developers to vary their classes with greater ease.
Let's propose a generic messenger interface that has the ability to send some form of message, Messenger.php:
<?php
interface Messenger
{
public function send($body);
}
One specific implementation of this interface is an InstantMessenger application, InstantMessenger.php:
<?php
class InstantMessenger implements Messenger
{
public function send($body)
{
echo "InstantMessenger: " . $body;
}
}
Similarly, we can do the same with an SMS application, SMS.php:
Read now
Unlock full access