课程: Python: Design Patterns (2021)

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Builder example

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 keeps it as its attribute. The concrete builder class called SkyLarkBuilder 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(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…

内容