How to reduce the DRY violation in this code

Chris Angelico rosuav at gmail.com
Tue Sep 27 13:26:50 EDT 2016


On Wed, Sep 28, 2016 at 3:08 AM, Gerald Britton
<gerald.britton at gmail.com> wrote:
>>
>> I have a class that takes a bunch of optional arguments. They're all
>> optional, with default values of various types. For simplicity, let's say
>> some are ints and some are floats: class Spam:
>> def __init__(self, bashful=10.0, doc=20.0, dopey=30.0,
>> grumpy=40, happy=50, sleepy=60, sneezy=70):
>> # the usual assign arguments to attributes dance...
>> self.bashful = bashful
>> self.doc = doc
>> # etc.
>
>
> This looks like a situation where the GoF Builder pattern might help

Can you elaborate on what "GoF builder" means? Presumably it's a
special case of the builder pattern, but my Google-fu has failed me on
this one.

ChrisA



More information about the Python-list mailing list