Re: [NetBeans]changing menuitems



On Sat, 26 Jul 2008 13:06:04 -0700, Mark Space wrote:

- these 2 methods :
public static GenListView getInstance() {
return instance;
}

This is pretty ugly. Returning a refernce to a private field? Ouch,
this totally breaks encapsulation

Huh?

In the second approach to implementing singletons, the public member
is a static factory method:

// Singleton with static factory
public class Elvis {
private static final Elvis INSTANCE = new Elvis();
private Elvis() { ... }
public static Elvis getInstance() { return INSTANCE; }
public void leaveTheBuilding() { ... }
}



Effective Java
Second Edition

page 17

ITEM 3: ENFORCE THE SINGLETON PROPERTY WITH A PRIVATE CONSTRUCTOR OR AN
ENUM TYPE


provided instance is final, it should be capitalized, else looks pretty
standard to me. ?


-Thufir
.



Relevant Pages

  • Re: Updates to a single class instance
    ... I tried to use a singleton, ... public class Collector{ ... private static Collector ref; ...
    (comp.lang.java.programmer)
  • Re: globals?
    ... singleton http://en.wikipedia.org/wiki/Singleton_pattern. ... Public Module myGlobals ... Those are therefore private to the module, ... myglobals.instance.somedata="Test String" ...
    (microsoft.public.dotnet.languages.vb)
  • Re: globals?
    ... And it is not a singleton that word is not used in the VB language. ... Public Module myGlobals ... Those are therefore private to the module, ... myglobals.instance.somedata="Test String" ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Singleton / Function
    ... The singleton pattern uses a private constructor a public static method and a ... private static instance of itself to pass back from the method. ... interface method, but I am not sure you need an interface for what you are ... > static ILocalPersistence* GetLocalPersistence; ...
    (microsoft.public.dotnet.framework)
  • Re: Shared globals between two classes
    ... I realize that public data ... Little change needed except for marking them 'private' and providing ... int getTXCount() const ... I recognise the Singleton structure may be somewhat confusing but please ...
    (alt.comp.lang.learn.c-cpp)