Re: Passing a lot of parameters in constructor?



Responding to Marshall...

Jerry Coffin said something like:

In article <1171216519.131931.144410@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
howachen@xxxxxxxxx says...

for example, a Person class, I need to create a person using, e.g.

Person peter = new Person('Peter', '....)

the object creation might involved over 30 parameters, the advantage
is this call is atomic, rather than something like, e.g.

Person peter = new Person();
peter.setName('Peter');
peter.setBirthPlace('....
...

Are there any platterns, suggestion or anti-plattern related to this
problem?

30 parameters is almost certainly excessive -- I'd suggest some sub-
objects to encapsulate some of the coherent pieces.


...[rip]...

Yep. My instincts here are two fold.

1. 30 parameters should be better identified into their abstracted relationships (like many have offered), *unless* the parameters are truly disparate in nature.

2. ...and if you find yourself with a need for 30 truly disparate parameters, then the overall design is almost certainly in question.

When the thread originally appeared here, that was pretty much the consensus, as I recall. All too often such objects show up as Singletons to hold a bunch of global data.


*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
Pathfinder Solutions
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
"Model-Based Translation: The Next Step in Agile Development". Email
info@xxxxxxxxxxxxxxxxx for your copy.
Pathfinder is hiring: http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH



.



Relevant Pages