From the course: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Builder pattern example - Python Tutorial
From the course: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
Builder pattern 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 pattern consisting of director, abstract builder, concrete builder and the object being built. The abstract builder class called "Builder" here creates a car object and keeps it as its attribute. The concrete builder class called Skylark Builder inherits from the abstract builder class right here and provides metals to be used by the director class. Let's add one more method to the concrete builder class which is the add underscore engine method. Type def add_engine (self):, 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.