From the course: Python: Design Patterns

Unlock this course with a free trial

Join today to access over 24,300 courses taught by industry experts.

Decorator

Decorator

- [Instructor] The Decorator design pattern is a structural pattern that allows users to add new features to existing objects without changing their structures. Python makes implementing the Decorator pattern very straightforward due to its built-in language feature. Our challenge here is to add additional features to an existing object dynamically without using subclassing. Here is our scenario. We start with a function displaying a "Hello, World!" message. We want to make the message look fancier by decorating it with additional tags, such as blink, as you can see here. Functions are objects in Python, and we can add additional features to these functions using the built-in Decorator in Python. Patterns such as Adapter, Composite, and Strategy are related to the Decorator pattern.

Contents