Grokking Design Patterns for Engineers and Managers
Vote

0% completed

Decorator Pattern

The Decorator Pattern adds behaviour to one object at run time, without touching its class and without a subclass per combination.

A repository needs logging. Then it needs caching. Then retries, then metrics. Different callers want different combinations, and some want them in a different order.

Inheritance cannot express that. LoggingCachingRetryingUserRepository works for exactly one combination, and the number of classes doubles with every concern you add. Four concerns is sixteen classes, and fifteen of them exist only because the sixteenth does.

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content