The Artima Developer Community
Sponsored Link

Java Buzz Forum
Use constructor chaining Part II

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Marc Logemann

Posts: 594
Nickname: loge
Registered: Sep, 2002

Marc Logemann is founder of www.logentis.de a Java consultancy
Use constructor chaining Part II Posted: Nov 6, 2004 4:21 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Marc Logemann.
Original Post: Use constructor chaining Part II
Feed Title: Marc's Java Blog
Feed URL: http://www.logemann.org/day/index_java.xml
Feed Description: Java related topics for all major areas. So you will see J2ME, J2SE and J2EE issues here.
Latest Java Buzz Posts
Latest Java Buzz Posts by Marc Logemann
Latest Posts From Marc's Java Blog

Advertisement

Since my entry on chaining constructors produced some feedback here and there, i want to go further on this topic.

First of all, i am not far away from Cedrics oppinion, in fact i am using private init() methods all over the place, but i also pointed out a risk on using them (see comments on cedrics blog). I am not totally with him on the point of readibility, but i agree on not putting too much code in a constructor.

One variant would be to use init() _and_ this-constructors. Here you call init() only in the last constructor in the chain to do the stuff you wanna do with your attributes and general state of the object.

BTW, using init() methods for construction is a pattern years in usage, so nobody would argue against it. Even the first versions of JBuilder and other IDEs used this approach when generating source code from their GUI builder.

Overall, we share one goal: defining one place where the initialisation of objects occur and trying to avoid having 10 places where the object will be initialised one step after another or even worse, 10 places with redundant init code.

Read: Use constructor chaining Part II

Topic: Bush threatened by offshoring or are still employed IT workers just too busy to vote? Previous Topic   Next Topic Topic: [Oct 27, 2004 14:46 PDT] 3 Links

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use