Is passing too many arguments to the constructor considered an anti-pattern?

前端 未结 5 889
独厮守ぢ
独厮守ぢ 2021-01-01 20:31

I am considering using the factory_boy library for API testing. An example from the documentation is:

class UserFactory(factory.Factory):
    class Meta:
            


        
5条回答
  •  清歌不尽
    2021-01-01 20:37

    If overloading were not a problem then every class in python could be reduced to a single method, which we could call doIt (....). As with everything, it's best to do things in moderation. Overloading any method with umpteen arguments is bad practice. Instead, allow the user to build up the object in bite-size chunks of related data. It's more logical. In your case, you could split the calls into names, communications, and perhaps other.

提交回复
热议问题