The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

This topic is READ ONLY
import-bot (20211) [Avatar] Offline
[Originally posted by cjacobs]


which method of implementation( Explicit VS Lazy Initialization ) of class
attributes is preffered when implementing GUIs. I have alway initialize my
JComponents in my "get methods". Wouldn't this slow the peformance of the


JButton button1 = new JButton( "Explicit" );


JButton button2;

private JButton getButton2() {
if( button2 == null )
button2 = new JButton( "Lazy" );
return button2;

You have method overhead, and every access to the instance variable includes a
conditional test.

Please, your comments or suggestion...

Thanks inadvance,

import-bot (20211) [Avatar] Offline
Re: Lazy Initialization vs Explicit Initialization!!!!
[Originally posted by wwake]

I usually start with explicit initialization
JButton b = new JButton("button");

I don't tend to do lazy initialization like you showed.

What I find, though, is that as your interface needs internationalization, or
becomes more dynamic, etc., that the simple initialization above has to be
done inside a method.

I usually start simple and "grow" what I need (trying to work in the "Extreme
Programming" stylesmilie

--Bill Wake