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.
Builder example - Python Tutorial
From the course: Python: Design Patterns
Builder example
- [Instructor] In this exercise, our goal is to build a car object and print its details. We'll do so by using the builder patterns, various participants, including director, abstract builder, concrete builder, and the object being built. The abstract builder class, called builder here, creates a car object and keep it as its attribute. The concrete builder class, called Skylark builder, inherits from the abstract builder class and provides methods to be used by the director class. Let's add one more method to the concrete builder class, which is the add_engine method. So type def add_engine, parentheses, self, colon, type self.car.engine, and set it to "Turbo Engine." The next part is to go back to the director class and complete the definition of the construct_car method. The director object is what actually builds a car. Let's create a new car object to get started. Type self._builder. This attribute is where the concrete builder object is stored, therefore type.create_new_car…
Contents
-
-
-
-
(Locked)
Factory57s
-
Factory example7m 37s
-
Solution: Factory2m 37s
-
(Locked)
Abstract Factory1m 46s
-
(Locked)
Abstract Factory example5m 57s
-
(Locked)
Singleton1m 39s
-
Singleton example7m 17s
-
(Locked)
Solution: Singleton2m 20s
-
(Locked)
Builder2m 3s
-
(Locked)
Builder example5m 59s
-
(Locked)
Prototype1m 30s
-
(Locked)
Prototype example7m 18s
-
(Locked)
-
-
-
-