From the course: Node.js: Design Patterns
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
The Composite pattern - Node.js Tutorial
From the course: Node.js: Design Patterns
The Composite pattern
- [Instructor] Sometimes, we want to perform the same operation on an individual element as we would a group of elements. Consider the grape.. I could tell you to eat a grape, and you'd know what to do with it. I could also tell you to eat these grapes, and so long as your hungry for grapes, you would then eat them all, one by one. In this example, the eat method can be used on a single grape, or a group of grapes. It will handle both cases accordingly. Composites work with trees, and when it comes to programming, trees are everywhere. One of the most common trees that we interact with is the file system, and the file system directories can be used to group files in other directories. The nodes that contain groups of other nodes are referred to as branches, and the file system, a file folder, represents a branch. If we traverse the tree, we will eventually end up with nodes that do not contain or group other…
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)
-
-