课程: Python: Design Patterns (2021)

今天就学习课程吧!

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

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.

内容