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 - Python Tutorial
From the course: Python: Design Patterns
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
-
-
-
-
-
(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)
-
-
-