Re: [NetBeans]changing menuitems



thufir wrote:


Huh?

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

Effective Java
Second Edition

That's an interesting way of looking at it. It might be correct, but I disagree. First of all, Singleton is the most abused design pattern, so anytime someone says "singleton!" I think one has to look at it carefully.

Second of all, the constructor is not private. Anyone can make a JMenuItem. It's constructor is public and you can't change that. Likewise, I doubt that GenViewList has a private constructor. (And if it does it's done for reasons others than singletoness.)

And third, I think, should it be a singleton? What if you make a top level appwindow with these menu, and then want to open a new document with the same top level window? Doesn't it make sense that this is going to cause problems if you try to force only one copy to exist in your code? I can see that the design might today call for only one menu bar, but tomorrow? This feels like boxing yourself in.

So I disagree that the GenViewList is or should be a singleton, which kinda blows the whole argument. It's just a class that has private fields (which I think the OP mentioned, are defined by the NetBeans GUI builder that way by default). And JMenuItem certainly isn't either.

Remember there's lots of reasons to make a field private than the Singleton pattern.

class Employee {
private String name;
//...
}

Passing out a reference to "name" doesn't make name a singleton....


.



Relevant Pages

  • Re: Singletons
    ... A singleton would usually have a private constructor to prevent ... but you're then breaking one of the rules of the singleton pattern. ... public function __construct ...
    (php.general)
  • Re: Singletons
    ... A singleton would usually have a private constructor to prevent ... but you're then breaking one of the rules of the singleton pattern. ... public function __construct ...
    (php.general)
  • 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: Observer Design Pattern
    ... require 'singleton' ... singletons would have a static factory method ") to make themselves useful. ... how does the factory method decide which constructor to invoke? ... Will the include statement make the constructors become private if they were declared public? ...
    (comp.object)
  • 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)