From the course: Python: Design Patterns
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
Composite example - Python Tutorial
From the course: Python: Design Patterns
Composite example
- [Instructor] Let's start by defining our abstract class, which is component. Nothing too much is done in the component class definition except for defining our interface method. Component underscore function. Let's move on to the child class definition. Since this one inherits from the component class, we'll have to say its parent is component. Right here. We'll have an attribute to store the name of the child. Type self dot name space assignment space args. The index is zero. What we're doing here is getting an argument from the instantiation process of the child class whose first argument happens to be the one we are going to be using for setting the name attribute. The second method here implements the abstract method component underscore function. Our implementation prints the name of the child. Let's move on to the composite class that also inherits from the abstract class component. We also need another attribute to store the name of the component object. Type self dot name…
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)
-
-
-