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 - Node.js Tutorial
From the course: Node.js: Design Patterns
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
The Adapter pattern2m 20s
-
(Locked)
Implementing an adapter6m 24s
-
(Locked)
The Proxy pattern2m 11s
-
(Locked)
Implementing a proxy5m 48s
-
(Locked)
The Composite pattern3m 12s
-
(Locked)
Implementing composites5m 59s
-
(Locked)
The Decorator pattern4m 3s
-
(Locked)
Implementing decorators4m 24s
-
(Locked)
-
-