This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Performance and the fly likes Performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Performance" Watch "Performance" New topic
Author

Performance

maha devan
Ranch Hand

Joined: Mar 16, 2004
Posts: 50
Hi
Anybody pls clarify my doubt
I am creating an object and passing 8 parameters to the constructor..
Can i pass any number of parameters to a constructor..??

I want to know
1. Is it a bad design
2. Will it affect the performance of my program in any way..
Anybody pls clarify my doubts
Thanks in Advance
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
MD: Can i pass any number of parameters to a constructor..??
Sure.
MD: Will it affect the performance of my program in any way..
I don't think so.
MD: Is it a bad design
Might be. Might not be.
Why can't you group the individual parameters with an object?
For example,
Replace

with

Where Name object will contain the firstName, lastName & the initial. And the Address object will contain the address details.


Mani
Quaerendo Invenietis
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi:
personally I think it is a bad design to pass 8 parametes to a constructor or a method. I think the max number should be 4, and less is better.
But again, it is my own opinion.


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

Martin Fowler agrees with what Hannah said in his classic refactoring book.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Jeanne Boyarsky:
Martin Fowler agrees with what Hannah said in his classic refactoring book.

See for example http://www.refactoring.com/catalog/introduceParameterObject.html


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Performance