• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Performance

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 42160
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Martin Fowler agrees with what Hannah said in his classic refactoring book.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic