From: Erik V. <eri...@hc...> - 2005-03-04 20:14:01
|
Yes, it should of course be protected. Lame excuse: it's 8 months ago I did my last Java before I started here, it seems the fine points get rusty soon.... Thanks, Erik. > -----Original Message----- > From: rai...@li... > [mailto:rai...@li...] On Behalf Of > Stewart Thain > Sent: 04 March 2005 19:12 > To: rai...@li... > Subject: RE: [Rails-devel] Stock market revisited > > Erik, > > >2. StockMarket is a singleton and should IMO be constructed as such. > >This means: private constructors, access only via a static get() > >method that returns the one instance (which is created the > first time, > >or from a static init block). > >In addition to safety, this removes the need to pass around object > >variables, > >as each class needing access to the stockmarket object can get it > >immediately by calling StockMarket.get(). > > Please think very carefully that you understand the > implications of making > the constructor "private" in Java when creating a singleton > class. A class > with a private constructor is implicitly final and cannot be > extended with a > subclass. As long as you want to prohibit subclasses of your > singleton, then > this is fine. However, if there is a possibility that it > might be useful at > some point for someone to create a subclass, then it is > better to make the > constructor "protected". > > Please note, I'm not suggeesting that StockMarket should not > be a singleton, > I'm simply making an observation about Java style and behaviour. > > You're going to be busy this weekend... have fun... I'm off > skiing, so I'll > b ehaving fun too! > > cheers > > Stewart > > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from > real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Rails-devel mailing list > Rai...@li... > https://lists.sourceforge.net/lists/listinfo/rails-devel > > |