课程: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Builder pattern example - Python教程
课程: 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…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。