mercredi 30 novembre 2016

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()
carBuilder.setSeats(2)
carBuilder.setSportsCar(true)
carBuilder.setTripComputer(true)
carBuilder.setGPS(false)
Car car = carBuilder.build()

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?

Aucun commentaire:

Enregistrer un commentaire