课程: Node.js: Design Patterns

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

The Decorator pattern

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…

内容