Re: [NetBeans]changing menuitems
- From: Mark Space <markspace@xxxxxxxxxxxxxx>
- Date: Sat, 26 Jul 2008 22:50:07 -0700
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....
.
- References:
- [NetBeans]changing menuitems
- From: Daniel Moyne
- Re: [NetBeans]changing menuitems
- From: Mark Space
- Re: [NetBeans]changing menuitems
- From: thufir
- [NetBeans]changing menuitems
- Prev by Date: Re: Text in if condition is not displayed in the browser
- Next by Date: adding a List of JTextField to the GUI
- Previous by thread: Re: [NetBeans]changing menuitems
- Next by thread: Re: [NetBeans]changing menuitems
- Index(es):
Relevant Pages
|