JavaScript – Decorator Pattern

Git Hub Code

This pattern makes use of a base and a decorator that wraps around that base.  With a reference to the base, the decorator can do something with the base value and then return it ‘decorated’

To Use:

  • Make Get Call

Screen Shot 2017-07-20 at 12.43.54 PM

  • Review the results

Screen Shot 2017-07-20 at 12.44.01 PM

According to reference #1, the actors are:

  • Component/Decorator Base
    • Component Base – This is the ‘non-decorated’ component.  For my implementation, this is AbsBase.js.
    • Decorator Base – This is a composite object that takes the base and modifies it. For my implementation, this is AbsDecoratorBase.js.

Screen Shot 2017-07-20 at 12.45.40 PM

  • Concrete Base/Concrete Decorator Base – These are the implementations.  For my implementation, I created objects in decoratorDriver.js.

Screen Shot 2017-07-20 at 12.45.17 PM

References

  1. http://www.blackwasp.co.uk/Decorator.aspx
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s