From the course: Python: Design Patterns
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Solution: Decorator - Python Tutorial
From the course: Python: Design Patterns
Solution: Decorator
- [Instructor] How did it go? Was it easier than you thought? That's the power of using design patterns. As indicated, let's create a decorator class that adds the HTML bold text. Copy the make_blink decorator code first. Ctrl + C. And then paste it here, Ctrl + V. Change the name to make_bold. And change the text to instead of blink, b. And then close tag, b. Which makes text bold in HTML. Now it's time to apply the decorators. Let's add the blink text by typing @make_blink. And next our bold text. Type @make_bold. That's it. It's time to test the code by clicking Test My Code. It shows the correct results.
Contents
-
-
-
-
-
(Locked)
Decorator1m 5s
-
(Locked)
Decorator example4m 43s
-
(Locked)
Solution: Decorator1m 55s
-
Proxy1m 22s
-
(Locked)
Proxy example5m 23s
-
(Locked)
Adapter48s
-
(Locked)
Adapter example6m 16s
-
(Locked)
Composite1m 21s
-
(Locked)
Composite example5m 25s
-
Solution: Composite1m 44s
-
(Locked)
Bridge1m 14s
-
(Locked)
Bridge example5m 31s
-
(Locked)
-
-
-