JavaScript – Bridge Pattern

GitHub Code

This post will deal with the bridge pattern.  This pattern’s goal (as I understand it) is to decouple an abstraction from its implementation so the two can be used independantly.

To run:
▪    Make GET Call
Screen Shot 2017-04-22 at 7.18.56 PM
▪    View results
Screen Shot 2017-04-22 at 7.19.07 PM

Diving in, there is an abstract class (as close as we can get with Javascript :)) called Agent.js.  This class has a name and office property.  Name is self explanatory.  Office is a reference to an implementation of IOffice.  In this case, Agent acts as a break between IOffice implementations and their calling agent implementations.
Screen Shot 2017-04-22 at 7.20.51 PM

IOffice.js has a method called giveSupport().  This interface is implemented by CiaOffice.js and FbiOffice.js.

Screen Shot 2017-04-22 at 7.21.00 PM

Screen Shot 2017-04-22 at 7.21.07 PM

Screen Shot 2017-04-22 at 7.21.14 PM

Then, an FBI or CIA agent can get support.

Screen Shot 2017-04-22 at 7.20.43 PM



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s