Builder pattern equivalent in Python

前端 未结 6 528
余生分开走
余生分开走 2020-12-23 09:00

In Java, you can use the builder pattern to provide a more readable means to instantiating a class with many parameters. In the builder pattern, one constructs a configurati

6条回答
  •  离开以前
    2020-12-23 09:48

    The builder pattern in Java can easily be achieved in python by using a variant of:

    MyClass(self, required=True, someNumber=, *args, **kwargs)

    where required and someNumber are an example to show required params with a default value and then reading for variable arguments while handling the case where there might be None

    In case you have not used variable arguments before, refer this

提交回复
热议问题