Cedric has has opined on Why chaining constructors is bad.
I have always disliked the names that constructors have in Java (e.g. the same name of the class).
I now consider having one constructor (which isn’t public) and then having static creation methods which call the constructor correctly:
Person p = Person.createWithLastName(lastname);
Person p = Person.createWithFullNames(firstname, lastname);
With an example like this, it is probably overkill. But if you find yourself with many constructors, and it is hard to remember which one you should use, then it is is nice to do this.
Of course, you often refactor these methods into a Creation Factory seperately.
November 5th, 2004 at 5:06 pm
But you are using different names again. Why not an overloaded create() method?
I can remember what parameters to pass but I will most likely not remember how you called that method (was it “withFullNames” or “withFullName”?).
November 5th, 2004 at 5:44 pm
I prefer being able to type in my IDE:
Person p = Person.CTRL SPACE
and choose the method that makes sense.
A better example is shown in “Refactoring to Patterns” which migrates:
public class Loan … {
public Loan(double commitment, int riskRating, Date maturity) {
this(commitment, 0.00, riskRating, maturity, null);
}
public Loan(double commitment, int riskRating, Date maturity, Date expiry) {
this(commitment, 0.00, riskRating, maturity, expiry);
}
public Loan(double commitment, double outstanding, int customerRating, Date maturity, Date expiry) {
this(null, commitment, outstanding, customerRating, maturity, expiry);
}
public Loan(CapitalStrategy capitalStrategy, double commitment, int riskRating, Date maturity, Date expiry) {
this(capitalStrategy, commitment, 0.00, riskRating, maturity, expiry);
}
public Loan(CapitalStrategy capitalStrategy, double commitment, double outstanding, int riskRating, Date maturity, Date expiry) {
…. do the work ….
}
}
to:
public class Loan … {
Loan(capitalStrategy, commitment, outstanding, riskRating, maturity, expiry);
createTermLoan(commitment, riskRating, maturity);
createTermLoan(capitalStrategy, commitment, outstanding, riskRating, maturity);
createRevolver(commitment, outstanding, riskRating, expiry);
createRevolver(capitalStrategy, commitment, outstanding, riskRating, maturity);
createRCTL(commitment, outstanding, riskRating, maturity, expiry);
createRCTL(capitalStrategy, commitment, outstanding, riskRating, maturity);
}
September 4th, 2007 at 11:03 am
Better a lean jade than an empty halter.
buy loss online pill weight [url=http://www.info.netfast.org/weight-loss-pill/site_map.html]buy loss online pill weight[/url]
September 4th, 2007 at 11:03 am
Better a lean jade than an empty halter.
buy loss online pill weight [url=http://www.info.netfast.org/weight-loss-pill/site_map.html]buy loss online pill weight[/url]
September 4th, 2007 at 11:03 am
Better a lean jade than an empty halter.
buy loss online pill weight [url=http://www.info.netfast.org/weight-loss-pill/site_map.html]buy loss online pill weight[/url]
September 5th, 2007 at 4:03 am
Be careless in your dress if you must, but keep a tidy soul.
buy inurl online tramadol [url=http://www.info.netfast.org/buy-tramadol/site_map.html]buy inurl online tramadol[/url]
September 5th, 2007 at 4:03 am
Be careless in your dress if you must, but keep a tidy soul.
buy inurl online tramadol [url=http://www.info.netfast.org/buy-tramadol/site_map.html]buy inurl online tramadol[/url]
September 5th, 2007 at 4:03 am
Be careless in your dress if you must, but keep a tidy soul.
buy inurl online tramadol [url=http://www.info.netfast.org/buy-tramadol/site_map.html]buy inurl online tramadol[/url]
September 6th, 2007 at 7:52 pm
Better one small fish than an empty dish.
bad credit payday loan [url=http://www.info.netfast.org/payday-loan/site_map.html]bad credit payday loan[/url]
September 6th, 2007 at 7:52 pm
Better one small fish than an empty dish.
bad credit payday loan [url=http://www.info.netfast.org/payday-loan/site_map.html]bad credit payday loan[/url]
September 6th, 2007 at 7:52 pm
Better one small fish than an empty dish.
bad credit payday loan [url=http://www.info.netfast.org/payday-loan/site_map.html]bad credit payday loan[/url]
September 8th, 2007 at 8:49 pm
Hello, for result
best chance!
card consolidate credit debtconsolidate debt
loan
September 9th, 2007 at 5:00 pm
Is that… in person?
buy prescription tramadol without [url=http://www.masthave.netfast.org/buy-tramadol/site_map.html]buy prescription tramadol without[/url]
September 9th, 2007 at 5:00 pm
Is that… in person?
buy prescription tramadol without [url=http://www.masthave.netfast.org/buy-tramadol/site_map.html]buy prescription tramadol without[/url]
September 9th, 2007 at 5:00 pm
Is that… in person?
buy prescription tramadol without [url=http://www.masthave.netfast.org/buy-tramadol/site_map.html]buy prescription tramadol without[/url]
September 13th, 2007 at 3:07 pm
Honesty is the best policy – when there is money in it.
buy tramadol hcl [url=http://schildau.info/buy-tramadol/site_map.html]buy tramadol hcl[/url]
September 13th, 2007 at 3:08 pm
Honesty is the best policy – when there is money in it.
buy tramadol hcl [url=http://schildau.info/buy-tramadol/site_map.html]buy tramadol hcl[/url]
September 15th, 2007 at 11:47 pm
7pMg5J eaxlzsysoedk, [url=http://wgddpfiuruyh.com/]wgddpfiuruyh[/url], [link=http://teslczwpajhm.com/]teslczwpajhm[/link], http://xohzpijdkjwv.com/
September 17th, 2007 at 4:32 pm
Another man’s mind is a closed book.
buy generic valium [url=http://www.learn.netfast.org/buy-valium/site_map.html]buy generic valium[/url]
September 18th, 2007 at 12:34 pm
It’s been such a long time since I last saw you.
buy generic valium [url=http://www.learn.netfast.org/buy-valium/site_map.html]buy generic valium[/url]
September 20th, 2007 at 7:45 pm
What’s new?
buy switch using valium [url=http://www.pharmacys.netfast.org/buy-valium/index.html]buy switch using valium[/url]
September 20th, 2007 at 10:10 pm
.0s0. brown pride dana hamm buy u a drink onion booty make it rain remix http://i-shot-myself.dfoop.com/i-ishotmyself-myself-shot.html i ishotmyself myself shot http://i-shot-myself.dfoop.com/i-shot-myself-nude.html i shot myself nude http://i-shot-myself.dfoop.com/i-shot-myself-naked.html i shot myself naked http://i-shot-myself.dfoop.com/girl-i-myself-shot.html girl i myself shot 4hh7-ffj-2dce http://i-shot-myself.dfoop.com/i-myself-shot-teen.html i myself shot teen .0n0.