From the course: Python: Design Patterns

Unlock the full course today

Join today to access over 23,200 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. Pattern 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 subclasses. Here is our scenario. We start with a function displaying a hello world message. You want to make the message look fancier by decorating it with additional tasks, 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