From the course: Node.js: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

The Decorator pattern

The Decorator pattern - Node.js Tutorial

From the course: Node.js: Design Patterns

Start my 1-month free trial

The Decorator pattern

- [Instructor] A decorator is a design pattern that allows us to dynamically attach additional properties and methods to existing objects. For example, let's say you wanted to build a camper van. You could start from scratch and design a brand new camper van, and then build it so that you could live in it. Or you could simply start with a plain old work van and add the features that you need to the already existing vehicle. With this approach you don't have to worry about building an engine, axles, or van body. You already have all that. All you need to worry about is modifying the van so that it has a bed, a sink, and a stove. Sometimes in our applications we already have the base objects that we need. We can decorate these objects with additional methods and properties to create many custom variations of the same object. The Gang of Four defines the intent of the decorator pattern to attach additional responsibilities to an object dynamically. Decorators provide a flexible…

Contents