Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance

 
maha devan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin Fowler agrees with what Hannah said in his classic refactoring book.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic