Surviving change
The Decorator Pattern, AngularJS
and You
Superheroic
with great power comes great responsibility

Over time, will our software become rickety ...
Or will it stand the test of time ...
Build for change ...
Picking "the right tool for the job."
What's your toolbox look like ?


Or

Bad tool choices lead to software that can't change
like furniture held together
by stripped screws ...

The decorator pattern
what is it?
a way
to change or extend
the behaviour of a service
without modifying the original service

The decorator pattern
why use it?
because
-
simpler services (single responsibility principle)
- simpler tests
- loose coupling / separating concerns
- more confidence (open/closed principle)
The decorator pattern
how to use it?
-
Register the decorator with the$injector using the $provide service:
-
Define the decorator:
The decorator should return the
decorated service instance.
Use case 1: extending $log

Use case 2: extending $resource
Other use cases:
- chaining decorators (TimeStamp$logDecorator decorates Publishing$logDecorator decorates $log)
- CachingWidgetsDecorator
- overriding/extending services or directives from external modules
?

links
- egghead.io on $provide.decorator
- decorating directives
The Decorator Pattern
By Joel Skrepnek
The Decorator Pattern
- 674