> If my constructor has a lot of arguments..e.g.
>
[quoted text clipped - 10 lines]
>
> so any recommendation for ctor having long arguments?

Signature
Eric Sosman
esosman@acm-dot-org.invalid
>> If my constructor has a lot of arguments..e.g.
>>
[quoted text clipped - 10 lines]
>>
>> so any recommendation for ctor having long arguments?
> A constructor with a lot of arguments has the same
> disadvantage as a method with a lot of arguments: it's
> hard for the programmer to remember what's what while
> writing or reading the code.
This is worse if all the arguments are Strings. One way to manage multiple
arguments is to give them different types:
public People( String name, Date birth, Gender gender );
// Gender is (type-safe) enum
In the given example, the ellipsis (...) tells us that even the class author
regards the remaining elements as less "essential" than the first three;
perhaps the { String, Date, Gender } tuple represents some sort of key.
Make such 'key' fields immutable; allowing change to elliptical fields is less
threatening to the People's identity. Set only the immutable fields in the
constructor.
Override equals() and hashCode() to use just the immutable fields. This
admits of caching the hash and the toString().
> However, moving arguments out of the constructor
> and providing mutator methods has disadvantages, too.
> Most obviously, it means you cannot use `final' for
> the variables that are now set through mutators.
Now you only need attribute methods for the mutable, i.e., "less essential"
fields.
> It can also make it more difficult to ensure that an object
> has a self-consistent state (a constructor can easily
> compare birth and death dates and throw an exception if
> they're out of order[*], but if the dates are controlled
> by mutators the consistency checking is more complex
> and more widely diffused).
Only the dangerous fields contribute to consistency; make those the immutable
fields. Only the safe fields will be mutable.
> [*] and if the person's name is not "P.D.Q. Bach."
>
[quoted text clipped - 17 lines]
> for a moment about how StringBuffer (or StringBuilder)
> gathers data for the eventual construction of a String.
A very useful pattern.
-Lew