课程: Python: Design Patterns (2021)
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Builder
- Builder is a solution to an anti-pattern called telescoping constructor. An anti-pattern is the opposite of the best programming practice and what we want to avoid. The telescoping constructor anti-pattern occurs when a software developer attempts to build a complex object using an excessive number of constructors. The builder pattern is trying to solve this problem. Think of a scenario in which you're trying to build a car. This test requires various car parts to be first constructed individually and then assembled. The builder pattern brings order to this chaotic process to remove unnecessary complexity as much as possible. It partitions the process of building a complex object into four different roles. The first role is a director in charge of actually building a product. The second role provides all the necessary interfaces required in building an object. We call this one an abstract builder because there'll be a…