[Tutor] class initialization with a lot of parameters

Alan Gauld alan.gauld at btinternet.com
Mon Nov 9 16:56:16 CET 2009


"C.T. Matsumoto" <c.t.matsumoto at gmail.com> wrote

> I'm making a class and the parameters I'm feeding the class is getting 
> quite
> large. I'm up to 8 now. Is there any rules of thumb for classes with a 
> lot of
> parameters?

There are no rules as such. Some of the Tkinter classes for excample
take a lot of arguments.

But you can usually simplify it by using default values and named 
parameters.
Also can any of the input values be grouped together into an object?
OOP means programming with objects, and that includes passing
whole objects aropund as arguments.

> class Foo(object):
>    def __init__(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8):

But with only a generic example to guide us we can only offer limited help.


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list