tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Einfeldt" <ralph.einfe...@uptime-isc.de>
Subject RE: about singletons (ot)
Date Wed, 29 Jan 2003 08:07:08 GMT
Although possible it has several drawbacks.

- Singletons that are just a class will never 
  be garbage collected. Instance singletons can 
  be, as soon as there is no reference to it.
  
- If you want to pass that singleton around, you loose 
  typesafty. (The singleton is just instance of 
  java.lang.Class and nothing else)

- You loose flexibility.
  E.g. Different singletons that implement the same 
  interface, and objects that do something with 
  instances that implement this interface.
  
- There can be several versions of the same class
  as each classloader can have its own version.
  (This can also happen, with your other approach

- You cant define interfaces for class that apply to
  the class. (Interfaces apply only to the instances
  of the class)

Not that I recommend not to do it, but when you do it
be aware of this drawbacks. (Some of the drawbacks can 
be overcome through the implementation of the class, 
but that is additional coding)


> -----Original Message-----
> From: Felipe Schnack [mailto:felipes@ritterdosreis.br]
> Sent: Tuesday, January 28, 2003 10:56 PM
> To: Tomcat Users List
> Subject: about singletons (ot) 
> 
> Normally we do that implementing a class that have its
> constructor as private, so no one can instantiate it,
> and a getInstance() method or something like it. We 
> wouldn't have the same kind of behavior if we simply 
> declare all class methods/fields as static?
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message