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.

Implementing composites

Implementing composites - Node.js Tutorial

From the course: Node.js: Design Patterns

Start my 1-month free trial

Implementing composites

- [Instructor] In the last lesson, we defined the composite design pattern, and we took a look at a place where it might be useful, a catalog. So I'm under the exercise files for chapter three, lesson six, and we're looking at our start folder. So these files, we created a few catalog items, and in the last lesson we also created a catalog group. We didn't actually program the catalog group class, so let's go ahead and do that. Let's go to our start folder, and create a new file, and we'll call it catalog group. And, inside of our catalog group file, what we want to do is make sure that our class for our catalog group, which will represent our branch, implements the same interface that our class for the catalog item would implement, so we want to make sure that we have a total, getter, so our catalog group will allow us to get a total, and a print method, so we can also print all of the details for our catalog group. And we'll go ahead and export our class. And if we look at our…

Contents