课程: Advanced Python: Build Hands-On Projects with Design Patterns (2023)

免费学习该课程!

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

Builder pattern

Builder pattern

- Builder is a creational design pattern. It addresses 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. 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 ConcreteBuilder…

内容