How to reduce the DRY violation in this code

Gerald Britton gerald.britton at gmail.com
Tue Sep 27 13:08:25 EDT 2016


>
> 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

-- 
Gerald Britton, MCSE-DP, MVP
LinkedIn Profile: http://ca.linkedin.com/in/geraldbritton



More information about the Python-list mailing list