The Artima Developer Community
Sponsored Link

Inclined to agree...

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Inclined to agree...

Posted by Mike Mannion on 26 Feb 1999, 2:36 AM

I'm inclined to agree with Shawn on this one.
Having read Bill's article, I took a look at a client application framework my team has designed and implemented over the past year.
Statics are used in just two circumstances:

1) Constants (static final)
2) Singletons (GOF style)

With the singletons I guess one has to take care that garbage collecting a singleton object can't result in any problems - as (I presume) is potentially the case if the singleton is responsible for maintaining some kind of dynamic state.
What's your take on this Bill? How can I ensure that a singleton object IS NOT garbage collected. Must I create an artificial reference to the object in question?

Just out of interest, Eiffel dispenses with statics altogether and instead provides a modifer for methods called "once".
Functions (plus Eiffel's equivalent of constructors) which use this keyword evaluate their results only once.
Once can thus dispense with constructions of the following form altogether:

public Singleton instance()
{
if (singleton == null)
{
singelton = new Singleton();
}
return singleton;
}

This applies to any "lazy evaluation" style method as well as singletons.

- Mike



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us