Sean Pianka Sean Pianka - 1 year ago 89
Python Question

Is the `Builder` design pattern obsolete in Python?

I was reading through this article on design patterns in Scala, and they presented the argument that the Builder pattern is relevant in Java, as it allows for code such as:

CarBuilder carBuilder = new CarBuilder()
Car car =

versus the more confusion-prone form:

Car car = new Car(2, true, true, false)

They later stated that:

In a language like Scala which lets you name arguments while passing
them in, the builder pattern is mostly obsolete...

Is this a similar situation for Python, as you're able to name keyword arguments in any call, or is there some reasonable application for this design pattern?

Answer Source

An authoritative answer can be found in the book Effective Java. Chapter 2 is where the famous Java Builder pattern by Josh Bloch originates. On page 15, it states,

The Builder pattern simulates named optional parameters as found in Ada and Python.

So the answer to your question is an emphatic yes. There is no need to simulate a pattern that exists natively in a language.

You may also be interested in this popular thread: Does Functional Programming Replace GoF Design Patterns?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download