Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
TypeScript Design Patterns

You're reading from  TypeScript Design Patterns

Product type Book
Published in Aug 2016
Publisher Packt
ISBN-13 9781785280832
Pages 256 pages
Edition 1st Edition
Languages
Author (1):
Vilic Vane Vilic Vane
Profile icon Vilic Vane

Decorator Pattern


Decorator Pattern adds new functionality to an object dynamically, usually without compromising the original features. The word decorator in Decorator Pattern does share something with the word decorator in the ES-next decorator syntax, but they are not exactly the same. Classical Decorator Pattern as a phrase would differ even more.

The classical Decorator Pattern works with a composite, and the brief idea is to create decorators as components that do the decorating work. As composite objects are usually processed recursively, the decorator components would get processed automatically. So it becomes your choice to decide what it does.

The inheritance hierarchy could be like the following structure shown:

The decorators are applied recursively like this:

There are two prerequisites for the decorators to work correctly: the awareness of context or object that a decorator is decorating, and the ability of the decorators being applied. The Composite Pattern can easily create...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}